BookmarkSubscribeRSS Feed
Solvej
Obsidian | Level 7

Dear all

 

I want to make a heat map of two discrete variables (there are 12 Groups in each). Do you have an suggestions on how to do this?

 

I use base sas and would just like to Group in positive and negatively correlations. Potentially also strong and less strongly correlations. I have tried to find a tutorial but have not been able to find one with two discrete variables.

 

Kind regards

 

Solvej

 

My sas two by two table looks like this (not real data)

 

Frequency             
Percent             
Row Pct             
Col PctABCDEFGHIJK LTotal
A10267914119140166312930464
0.220.560.150.190.32.573.030.351.360.020.630.6510.03
2.165.61.511.943.0225.6530.173.4513.580.226.256.47 
30.37.1413.467.899.7212.918.9713.569.817.698.928.9 
B5140143251212011129252
0.113.030.020.090.060.540.260.020.430.020.240.635.45
1.9855.560.41.591.199.924.760.47.940.44.3711.51 
15.1538.461.923.512.082.710.770.853.127.693.388.61 
C052627423212458
00.110.560.040.150.090.040.060.040.020.040.091.25
08.6244.833.4512.076.93.455.173.451.723.456.9 
01.37501.754.860.430.132.540.317.690.621.19 
D0106151030613292
00.0201.320.110.220.0600.130.020.060.041.99
01.09066.35.4310.873.2606.521.093.262.17 
00.27053.513.471.080.1900.937.690.920.59 
E11312541072104095
0.020.280.020.041.170.220.150.040.0200.0902.05
1.0513.681.052.1156.8410.537.372.111.0504.210 
3.033.571.921.7537.51.080.451.690.1601.230 
F2755151955077811539335997
0.041.620.110.320.4111.891.670.172.490.062.010.7621.56
0.27.520.51.51.9155.177.720.811.530.39.333.51 
6.0620.69.6213.1613.1959.654.946.7817.9123.0828.6210.39 
G613562477126210303161425
0.130.280.110.130.521.6727.290.220.0600.060.3530.82
0.420.910.350.421.685.488.560.70.2100.211.12 
18.183.579.625.2616.678.3580.98.470.4700.924.75 
H2604919267010062154
0.040.1300.090.190.410.561.510.2200.130.043.33
1.33.902.65.8412.3416.8845.456.4903.91.3 
6.061.6503.516.252.061.6759.321.5601.850.59 
I7524446416338203529600
0.151.120.090.090.091.380.350.068.2600.760.6312.98
1.178.670.670.670.6710.672.670.563.6705.834.83 
21.2114.297.693.512.786.941.032.5459.5010.778.61 
J03000100440012
00.060000.02000.090.09000.26
0250008.330033.3333.3300 
00.820000.11000.6230.7700 
K01612230852911338235
00.350.020.040.040.650.170.110.630.022.880.175.08
06.810.430.850.8512.773.42.1312.340.4356.63.4 
04.41.921.751.393.250.514.244.527.6940.922.37 
L0142531370716182240
00.30.040.110.060.280.1500.150.020.133.945.19
05.830.832.081.255.422.9202.920.422.575.83 
03.853.854.392.081.410.4501.097.691.8554.01 
Total33364521141449221560118642133253374624
0.717.871.122.473.1119.9433.742.5513.880.287.037.29100
11 REPLIES 11
PaigeMiller
Diamond | Level 26

I don't understand your table, it is certainly not a correlation matrix, but to create a colored table of anything, you can use PROC REPORT. See this example: http://www.caloxy.com/papers/69-TUT.pdf

--
Paige Miller
Ksharp
Super User

@Rick_SAS has already written a couple of blogs about it.

Or try 

proc sgplot data=

heatmap ...........

 

heatmapparm ..........

PaigeMiller
Diamond | Level 26

 

@Ksharp

Does SGPLOT produce colored tables?

--
Paige Miller
WarrenKuhfeld
Ammonite | Level 13

These might be of interest.

https://blogs.sas.com/content/graphicallyspeaking/2017/12/11/displaying-upper-lower-triangle-correla...

 

support.sas.com/resources/papers/proceedings17/SAS0312-2017.pdf 

PaigeMiller
Diamond | Level 26

@WarrenKuhfeld wrote:

These might be of interest.

https://blogs.sas.com/content/graphicallyspeaking/2017/12/11/displaying-upper-lower-triangle-correla...

 

support.sas.com/resources/papers/proceedings17/SAS0312-2017.pdf 


I was not aware of these. Impressive. 

 

Still, I would think creating such a colored correlation matrix (or other form of colored table) would somehow get easier over time, perhaps even to the point where it was built in to SAS, so people wouldn't need such complicated code to do this.

--
Paige Miller
Ksharp
Super User

Sure.

Check 

Solvej
Obsidian | Level 7
I tried writing this

proc sgplot data=diagnose noautolegend; heatmap x= Hdiaggrup Y= epiHdiaggrup / freq=Count discretex discretey colormodel=TwoColorRamp outline; run;

I get the following error statement
372 proc sgplot data=diagnose noautolegend; heatmapparm x= Hdiaggrup Y= epiHdiaggrup
-----------
180
372! / freq=Count discretex discretey
ERROR 180-322: Statement is not valid or it is used out of proper order.

What can be wrong
Solvej
Obsidian | Level 7

I tried writing this

proc sgplot data=diagnose noautolegend;

heatmap x= Hdiaggrup Y= epiHdiaggrup / freq=Count discretex discretey colormodel=TwoColorRamp outline; run;

I get the following error statement
372 proc sgplot data=diagnose noautolegend; heatmapparm x= Hdiaggrup Y= epiHdiaggrup
-----------
180
372! / freq=Count discretex discretey
ERROR 180-322: Statement is not valid or it is used out of proper order.

What can be wrong?

Ksharp
Super User

Maybe your SAS version is too old. Your sas at least SAS 9.4m4

Or you could try PROC IML ,check @Rick_SAS 's blog 

http://blogs.sas.com/content/iml/

Ksharp
Super User

Maybe your SAS version is too old. Your sas at least SAS 9.4m4

Or you could try PROC IML ,check @Rick_SAS 's blog 

http://blogs.sas.com/content/iml/

DanH_sas
SAS Super FREQ

Given the nature of your data, can you  use a HEATMAPPARM instead of a HEATMAP? HEATMAPPARM was released before HEATMAP. Try something like this:

 

proc sgplot data=diagnose noautolegend;

heatmapparm x= Hdiaggrup Y= epiHdiaggrup colorrresponse=Count /  discretex discretey colormodel=TwoColorRamp outline;

run;

 

Hope this helps!

Dan

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1752 views
  • 2 likes
  • 5 in conversation