I want to create two heat maps from two datasets with similar structure.
The first dataset, however, does not have data for all x-y heat map combinations in the larger row x col panel structure, and this causes a problem in the heat map colour assignment.
Here is data and code:
data One;
input _Region $ 1-2 _Substance $ 7-20 _Scale $ 22-28 SW_Signif1 $ 31 N 36-40 Pct 42-47;
datalines;
AU cricket daily A 304 0.0556
AU cricket daily B 5168 0.9444
AU cricket monthly A 11 0.0611
AU cricket monthly B 169 0.9389
AU cricket yearly A 1 0.0667
AU cricket yearly B 14 0.9333
AU facebook daily A 490 0.1046
AU facebook daily B 4193 0.8954
AU facebook monthly A 5 0.0321
AU facebook monthly B 151 0.9679
AU facebook yearly B 13 1
AU superannuation daily A 1709 0.3123
AU superannuation daily B 3763 0.6877
AU superannuation monthly A 5 0.0278
AU superannuation monthly B 175 0.9722
AU superannuation yearly B 15 1
AU weather daily A 106 0.0194
AU weather daily B 5366 0.9806
AU weather monthly A 9 0.05
AU weather monthly B 171 0.95
AU weather yearly B 15 1
AU youtube daily A 228 0.048
AU youtube daily B 4518 0.952
AU youtube monthly A 1 0.0064
AU youtube monthly B 155 0.9936
AU youtube yearly B 13 1
US facebook daily A 307 0.0647
US facebook daily B 4441 0.9353
US facebook monthly A 6 0.0385
US facebook monthly B 150 0.9615
US facebook yearly B 13 1
US youtube daily A 319 0.0672
US youtube daily B 4429 0.9328
US youtube monthly A 1 0.0064
US youtube monthly B 155 0.9936
US youtube yearly B 13 1
WW clenbuterol daily A 18 0.0099
WW clenbuterol daily B 1808 0.9901
WW clenbuterol monthly A 3 0.0175
WW clenbuterol monthly B 168 0.9825
WW codeine daily A 16 0.0088
WW codeine daily B 1810 0.9912
WW codeine monthly A 6 0.0351
WW codeine monthly B 165 0.9649
WW facebook daily A 222 0.0468
WW facebook daily B 4526 0.9532
WW facebook monthly A 5 0.0321
WW facebook monthly B 151 0.9679
WW facebook yearly B 13 1
WW fentanyl daily A 21 0.0115
WW fentanyl daily B 1805 0.9885
WW fentanyl monthly A 4 0.0234
WW fentanyl monthly B 167 0.9766
WW mdma daily A 238 0.1303
WW mdma daily B 1588 0.8697
WW mdma monthly A 3 0.0175
WW mdma monthly B 168 0.9825
WW modafinil daily A 118 0.0646
WW modafinil daily B 1708 0.9354
WW modafinil monthly A 1 0.0058
WW modafinil monthly B 170 0.9942
WW pregabalin daily A 240 0.1314
WW pregabalin daily B 1586 0.8686
WW pregabalin monthly A 11 0.0643
WW pregabalin monthly B 160 0.9357
WW youtube daily A 214 0.0451
WW youtube daily B 4534 0.9549
WW youtube monthly A 2 0.0128
WW youtube monthly B 154 0.9872
WW youtube yearly B 13 1
;
run;
data Two;
input _Region $ 1-2 _Substance $ 7-20 _Scale $ 22-28 SW_Signif1 $ 31 N 36-40 Pct 42-47;
datalines;
AU clenbuterol daily A 203 0.8286
AU clenbuterol daily B 42 0.1714
AU clenbuterol monthly A 70 0.3933
AU clenbuterol monthly B 108 0.6067
AU codeine daily A 58 0.2367
AU codeine daily B 187 0.7633
AU codeine monthly A 56 0.3128
AU codeine monthly B 123 0.6872
AU cricket daily A 244 1
AU cricket monthly A 172 0.9609
AU cricket monthly B 7 0.0391
AU facebook daily A 243 0.9918
AU facebook daily B 2 0.0082
AU facebook monthly A 138 0.9928
AU facebook monthly B 1 0.0072
AU fentanyl daily A 226 0.9224
AU fentanyl daily B 19 0.0776
AU fentanyl monthly A 67 0.3722
AU fentanyl monthly B 113 0.6278
AU mdma daily A 176 0.7184
AU mdma daily B 69 0.2816
AU mdma monthly A 41 0.2278
AU mdma monthly B 139 0.7722
AU modafinil daily A 71 0.2898
AU modafinil daily B 174 0.7102
AU modafinil monthly A 80 0.4444
AU modafinil monthly B 100 0.5556
AU pregabalin daily A 127 0.5184
AU pregabalin daily B 118 0.4816
AU pregabalin monthly A 77 0.4425
AU pregabalin monthly B 97 0.5575
AU superannuation daily A 121 0.4939
AU superannuation daily B 124 0.5061
AU superannuation monthly A 84 0.4667
AU superannuation monthly B 96 0.5333
AU youtube daily A 242 0.9918
AU youtube daily B 2 0.0082
AU youtube monthly A 152 0.9935
AU youtube monthly B 1 0.0065
US clenbuterol daily A 102 0.4163
US clenbuterol daily B 143 0.5837
US clenbuterol monthly A 129 0.7207
US clenbuterol monthly B 50 0.2793
US codeine daily A 161 0.6571
US codeine daily B 84 0.3429
US codeine monthly A 80 0.4444
US codeine monthly B 100 0.5556
US cricket daily A 230 0.9388
US cricket daily B 15 0.0612
US cricket monthly A 178 0.9944
US cricket monthly B 1 0.0056
US facebook daily A 245 1
US facebook monthly A 139 0.9929
US facebook monthly B 1 0.0071
US fentanyl daily A 244 1
US fentanyl monthly A 157 0.8722
US fentanyl monthly B 23 0.1278
US mdma daily A 210 0.8607
US mdma daily B 34 0.1393
US mdma monthly A 55 0.3073
US mdma monthly B 124 0.6927
US modafinil daily A 82 0.3347
US modafinil daily B 163 0.6653
US modafinil monthly A 70 0.3911
US modafinil monthly B 109 0.6089
US pregabalin daily A 42 0.1714
US pregabalin daily B 203 0.8286
US pregabalin monthly A 11 0.0611
US pregabalin monthly B 169 0.9389
US superannuation daily A 223 0.9139
US superannuation daily B 21 0.0861
US superannuation monthly A 50 0.2778
US superannuation monthly B 130 0.7222
US youtube daily A 244 1
US youtube monthly A 151 1
WW clenbuterol daily A 65 0.2653
WW clenbuterol daily B 180 0.7347
WW clenbuterol monthly A 29 0.1611
WW clenbuterol monthly B 151 0.8389
WW codeine daily A 156 0.6367
WW codeine daily B 89 0.3633
WW codeine monthly A 137 0.7654
WW codeine monthly B 42 0.2346
WW cricket daily A 245 1
WW cricket monthly A 179 1
WW facebook daily A 245 1
WW facebook monthly A 127 0.9769
WW facebook monthly B 3 0.0231
WW fentanyl daily A 244 1
WW fentanyl monthly A 155 0.8611
WW fentanyl monthly B 25 0.1389
WW mdma daily A 183 0.7469
WW mdma daily B 62 0.2531
WW mdma monthly A 78 0.4333
WW mdma monthly B 102 0.5667
WW modafinil daily A 81 0.3306
WW modafinil daily B 164 0.6694
WW modafinil monthly A 91 0.5056
WW modafinil monthly B 89 0.4944
WW pregabalin daily A 193 0.7878
WW pregabalin daily B 52 0.2122
WW pregabalin monthly A 89 0.4944
WW pregabalin monthly B 91 0.5056
WW superannuation daily A 98 0.4
WW superannuation daily B 147 0.6
WW superannuation monthly A 107 0.5944
WW superannuation monthly B 73 0.4056
WW youtube daily A 245 1
WW youtube monthly A 151 1
;
run;
%MACRO CommonCode(dset=);
proc print data=&dset.;run;
PROC SGPANEL
NOAUTOLEGEND
DATA=&dset.;
PANELBY _Region _Scale /LAYOUT=LATTICE NOVARNAME ONEPANEL NOWALL NOBORDER;
ROWAXIS DISPLAY=(NOLABEL) DISCRETEORDER=DATA;
COLAXIS DISPLAY=(NOLABEL);
HEATMAP X=SW_Signif1 Y=_Substance / FREQ=N COLORSTAT=PCT DISCRETEX DISCRETEY ;
TEXT X=SW_Signif1 Y=_Substance TEXT=Pct;
FORMAT Pct PERCENT8.2;
TITLE "&dset.";
RUN;
%MEND CommonCode;
%CommonCode(dset=One);
%CommonCode(dset=Two);
One
Two
The issue is easily seen when looking at the red which is meant to get darker as values get closer to 100%
If one looks at heat map two, then each set of A/B columns for AU, US, and WW are correctly coloured within that set.
However, for heat map one, high values only appear in red when all three of the panel columns have values, and even then, only one high value from the three sets appears in red (e.g., the youtube or facebook values).
If I change it to sgplot with by _Region _scale; to generate separate plots for each combination used in the panel, the colours are assigned correctly (with the exception of those having 100% where it's blue, instead of red). So I suspect the problem is not in the heatmap statement, but in how the panel is interacting with it.
My question, though, is how do I get consistently all the values close to 100% displayed in red, despite the portions of the panel which have no data?
Any help would be appreciated.
You could try this statement. Since you already calcualted Pct .
HEATMAP X=SW_Signif1 Y=_Substance / /* FREQ=N COLORSTAT=PCT */ COLORRESPONSE=pct DISCRETEX DISCRETEY ;
You could try this statement. Since you already calcualted Pct .
HEATMAP X=SW_Signif1 Y=_Substance / /* FREQ=N COLORSTAT=PCT */ COLORRESPONSE=pct DISCRETEX DISCRETEY ;
If you really care about scale problem, you could consider standardize PCT before plot it .
data one; set one; _pct=pct; run; data two; set two; _pct=pct; run; proc stdize data=one out=o;var _pct;run; proc stdize data=two out=t;var _pct;run; %MACRO CommonCode(dset=); proc print data=&dset.;run; PROC SGPANEL NOAUTOLEGEND DATA=&dset.; PANELBY _Region _Scale /LAYOUT=LATTICE NOVARNAME ONEPANEL NOWALL NOBORDER; ROWAXIS DISPLAY=(NOLABEL) DISCRETEORDER=DATA; COLAXIS DISPLAY=(NOLABEL); HEATMAP X=SW_Signif1 Y=_Substance / /* FREQ=N COLORSTAT=PCT */ COLORRESPONSE=_pct DISCRETEX DISCRETEY ; TEXT X=SW_Signif1 Y=_Substance TEXT=Pct /strip; FORMAT Pct PERCENT8.2; TITLE "&dset."; RUN; %MEND CommonCode; %CommonCode(dset=O) %CommonCode(dset=T)
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: