Heman
Heman

Reputation: 3

converting 3 variable into a matrix form to create a heatmap in SAS

I'm trying to convert 3 vairables into a matrix, for expample if you have the following:

(CHAR) (char) (num)

Var1 Var2 Var3

A B 1

C D 2

E F 3

A D 4

A F 5

C B 6

C F 7

E B 8

E D 9

Any ideas on how to convert the above three variables into this form of matrix below and my goal is to construct a heatmap using this matix

B   D   F

A 1 4 5

C 6 2 7

E 8 9 3

Can anyone help me do this in SAS, either using SAS/IML or other Procedure? Thanks!

Upvotes: 0

Views: 227

Answers (2)

Rick
Rick

Reputation: 1210

Assuming you are using a recent version of SAS/IML (13.1 or later), use the HEATMAPCONT or HEATMAPDISC call:

proc iml;
m = {1 4 5,
     6 2 7,
     8 9 3};
call heatmapcont(m) xvalues={B D F} yvalues={A C E};

For details, see Creating heat maps in SAS/IML

Upvotes: 1

Lovnlust
Lovnlust

Reputation: 1537

It will be better if you post your code first then ask questions.

I think proc transpose is the fastest solution.

data _t1;
input var1 $ var2 $ var3 5.;
cards;
A B 1 
C D 2
E F 3
A D 4
A F 5
C B 6
C F 7
E B 8
E D 9
run;

proc sort data=_t1;by var1;run;

proc transpose data=_t1 out=_t2(drop=_name_ rename=(var1=HereUpToYou));
by var1;
var var3;
id var2;
run;

Upvotes: 0

Related Questions