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 Pct | A | B | C | D | E | F | G | H | I | J | K | L | Total |
A | 10 | 26 | 7 | 9 | 14 | 119 | 140 | 16 | 63 | 1 | 29 | 30 | 464 |
0.22 | 0.56 | 0.15 | 0.19 | 0.3 | 2.57 | 3.03 | 0.35 | 1.36 | 0.02 | 0.63 | 0.65 | 10.03 | |
2.16 | 5.6 | 1.51 | 1.94 | 3.02 | 25.65 | 30.17 | 3.45 | 13.58 | 0.22 | 6.25 | 6.47 | ||
30.3 | 7.14 | 13.46 | 7.89 | 9.72 | 12.91 | 8.97 | 13.56 | 9.81 | 7.69 | 8.92 | 8.9 | ||
B | 5 | 140 | 1 | 4 | 3 | 25 | 12 | 1 | 20 | 1 | 11 | 29 | 252 |
0.11 | 3.03 | 0.02 | 0.09 | 0.06 | 0.54 | 0.26 | 0.02 | 0.43 | 0.02 | 0.24 | 0.63 | 5.45 | |
1.98 | 55.56 | 0.4 | 1.59 | 1.19 | 9.92 | 4.76 | 0.4 | 7.94 | 0.4 | 4.37 | 11.51 | ||
15.15 | 38.46 | 1.92 | 3.51 | 2.08 | 2.71 | 0.77 | 0.85 | 3.12 | 7.69 | 3.38 | 8.61 | ||
C | 0 | 5 | 26 | 2 | 7 | 4 | 2 | 3 | 2 | 1 | 2 | 4 | 58 |
0 | 0.11 | 0.56 | 0.04 | 0.15 | 0.09 | 0.04 | 0.06 | 0.04 | 0.02 | 0.04 | 0.09 | 1.25 | |
0 | 8.62 | 44.83 | 3.45 | 12.07 | 6.9 | 3.45 | 5.17 | 3.45 | 1.72 | 3.45 | 6.9 | ||
0 | 1.37 | 50 | 1.75 | 4.86 | 0.43 | 0.13 | 2.54 | 0.31 | 7.69 | 0.62 | 1.19 | ||
D | 0 | 1 | 0 | 61 | 5 | 10 | 3 | 0 | 6 | 1 | 3 | 2 | 92 |
0 | 0.02 | 0 | 1.32 | 0.11 | 0.22 | 0.06 | 0 | 0.13 | 0.02 | 0.06 | 0.04 | 1.99 | |
0 | 1.09 | 0 | 66.3 | 5.43 | 10.87 | 3.26 | 0 | 6.52 | 1.09 | 3.26 | 2.17 | ||
0 | 0.27 | 0 | 53.51 | 3.47 | 1.08 | 0.19 | 0 | 0.93 | 7.69 | 0.92 | 0.59 | ||
E | 1 | 13 | 1 | 2 | 54 | 10 | 7 | 2 | 1 | 0 | 4 | 0 | 95 |
0.02 | 0.28 | 0.02 | 0.04 | 1.17 | 0.22 | 0.15 | 0.04 | 0.02 | 0 | 0.09 | 0 | 2.05 | |
1.05 | 13.68 | 1.05 | 2.11 | 56.84 | 10.53 | 7.37 | 2.11 | 1.05 | 0 | 4.21 | 0 | ||
3.03 | 3.57 | 1.92 | 1.75 | 37.5 | 1.08 | 0.45 | 1.69 | 0.16 | 0 | 1.23 | 0 | ||
F | 2 | 75 | 5 | 15 | 19 | 550 | 77 | 8 | 115 | 3 | 93 | 35 | 997 |
0.04 | 1.62 | 0.11 | 0.32 | 0.41 | 11.89 | 1.67 | 0.17 | 2.49 | 0.06 | 2.01 | 0.76 | 21.56 | |
0.2 | 7.52 | 0.5 | 1.5 | 1.91 | 55.17 | 7.72 | 0.8 | 11.53 | 0.3 | 9.33 | 3.51 | ||
6.06 | 20.6 | 9.62 | 13.16 | 13.19 | 59.65 | 4.94 | 6.78 | 17.91 | 23.08 | 28.62 | 10.39 | ||
G | 6 | 13 | 5 | 6 | 24 | 77 | 1262 | 10 | 3 | 0 | 3 | 16 | 1425 |
0.13 | 0.28 | 0.11 | 0.13 | 0.52 | 1.67 | 27.29 | 0.22 | 0.06 | 0 | 0.06 | 0.35 | 30.82 | |
0.42 | 0.91 | 0.35 | 0.42 | 1.68 | 5.4 | 88.56 | 0.7 | 0.21 | 0 | 0.21 | 1.12 | ||
18.18 | 3.57 | 9.62 | 5.26 | 16.67 | 8.35 | 80.9 | 8.47 | 0.47 | 0 | 0.92 | 4.75 | ||
H | 2 | 6 | 0 | 4 | 9 | 19 | 26 | 70 | 10 | 0 | 6 | 2 | 154 |
0.04 | 0.13 | 0 | 0.09 | 0.19 | 0.41 | 0.56 | 1.51 | 0.22 | 0 | 0.13 | 0.04 | 3.33 | |
1.3 | 3.9 | 0 | 2.6 | 5.84 | 12.34 | 16.88 | 45.45 | 6.49 | 0 | 3.9 | 1.3 | ||
6.06 | 1.65 | 0 | 3.51 | 6.25 | 2.06 | 1.67 | 59.32 | 1.56 | 0 | 1.85 | 0.59 | ||
I | 7 | 52 | 4 | 4 | 4 | 64 | 16 | 3 | 382 | 0 | 35 | 29 | 600 |
0.15 | 1.12 | 0.09 | 0.09 | 0.09 | 1.38 | 0.35 | 0.06 | 8.26 | 0 | 0.76 | 0.63 | 12.98 | |
1.17 | 8.67 | 0.67 | 0.67 | 0.67 | 10.67 | 2.67 | 0.5 | 63.67 | 0 | 5.83 | 4.83 | ||
21.21 | 14.29 | 7.69 | 3.51 | 2.78 | 6.94 | 1.03 | 2.54 | 59.5 | 0 | 10.77 | 8.61 | ||
J | 0 | 3 | 0 | 0 | 0 | 1 | 0 | 0 | 4 | 4 | 0 | 0 | 12 |
0 | 0.06 | 0 | 0 | 0 | 0.02 | 0 | 0 | 0.09 | 0.09 | 0 | 0 | 0.26 | |
0 | 25 | 0 | 0 | 0 | 8.33 | 0 | 0 | 33.33 | 33.33 | 0 | 0 | ||
0 | 0.82 | 0 | 0 | 0 | 0.11 | 0 | 0 | 0.62 | 30.77 | 0 | 0 | ||
K | 0 | 16 | 1 | 2 | 2 | 30 | 8 | 5 | 29 | 1 | 133 | 8 | 235 |
0 | 0.35 | 0.02 | 0.04 | 0.04 | 0.65 | 0.17 | 0.11 | 0.63 | 0.02 | 2.88 | 0.17 | 5.08 | |
0 | 6.81 | 0.43 | 0.85 | 0.85 | 12.77 | 3.4 | 2.13 | 12.34 | 0.43 | 56.6 | 3.4 | ||
0 | 4.4 | 1.92 | 1.75 | 1.39 | 3.25 | 0.51 | 4.24 | 4.52 | 7.69 | 40.92 | 2.37 | ||
L | 0 | 14 | 2 | 5 | 3 | 13 | 7 | 0 | 7 | 1 | 6 | 182 | 240 |
0 | 0.3 | 0.04 | 0.11 | 0.06 | 0.28 | 0.15 | 0 | 0.15 | 0.02 | 0.13 | 3.94 | 5.19 | |
0 | 5.83 | 0.83 | 2.08 | 1.25 | 5.42 | 2.92 | 0 | 2.92 | 0.42 | 2.5 | 75.83 | ||
0 | 3.85 | 3.85 | 4.39 | 2.08 | 1.41 | 0.45 | 0 | 1.09 | 7.69 | 1.85 | 54.01 | ||
Total | 33 | 364 | 52 | 114 | 144 | 922 | 1560 | 118 | 642 | 13 | 325 | 337 | 4624 |
0.71 | 7.87 | 1.12 | 2.47 | 3.11 | 19.94 | 33.74 | 2.55 | 13.88 | 0.28 | 7.03 | 7.29 | 100 |
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
@Rick_SAS has already written a couple of blogs about it.
Or try
proc sgplot data=
heatmap ...........
heatmapparm ..........
These might be of interest.
@WarrenKuhfeld wrote:
These might be of interest.
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.
Sure.
Check WarrenKuhfeld and other's blog Graph Speaking .
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?
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
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.