Reputation: 141
I am looking to create a heat map in SAS. I have a large data set of x,y coordinates and that's it. From reading into everything, I need to create a "count" for the coordinates using something like this:
proc kde data=dataSet;
bivar X Y / out=outputDataSet;
run;
Next, I need to create a template for the heatchart--I have found this sample code, but I'm not sure what everything is doing:
proc template;
define statgraph heatmapparm;
begingraph;
layout overlay;
heatmapparm x=value1 y=value2 colorresponse=count /
name="heatmapparm" xbinaxis=false ybinaxis=false;
continuouslegend "heatmapparm" / location=outside valign=bottom;
endlayout;
endgraph;
end;
run;
I'm assuming I need to insert my variables into the x and y spots, and the count into the colorresponse place and then use a code like this to get the heatmap:
proc sgrender data=outputDataSet template=heatmapparm;
run;
This code leads to an error message and no graph output because it is "missing an argument." Any help would be great. Thanks!
Upvotes: 3
Views: 2550
Reputation: 63424
Rick Wicklin does a good job explaining this on his blog, The DO Loop.
You should look up a tutorial on Graph Template Language (GTL), such as Sanjay Matange (the lead developer of the ODS Graphics system including GTL). He's written a book on the topic, or you can read his papers, such as this introduction.
Basically, yes, you should fill in the x= and y= with your x/y variables, colorresponse= with the variable that defines the count (how red/blue to make it).
Here's an example. Here we use dynamic variables
, which mean you can define the relevant variable in the SGRENDER
step. Rick shows this in his blog post, I use a slightly simplified version. You can likely use the PROC TEMPLATE
exactly as is, just changing the SGRENDER to refer to your dataset and your variables. The test
dataset is just made-up data that will generate an interesting heat map.
proc template;
define statgraph heatmapparm;
dynamic _X _Y _Z;
begingraph;
layout overlay;
heatmapparm x=_X y=_Y colorresponse=_Z/
name="heatmapparm" xbinaxis=false ybinaxis=false;
continuouslegend "heatmapparm" / location=outside valign=bottom;
endlayout;
endgraph;
end;
run;
data test;
call streaminit(7);
do x = 1 to 10;
do y = 1 to 10;
count_var = rand('Normal',(x+y)/2);
output;
end;
end;
run;
proc sgrender data=test template=heatmapparm;
dynamic _X='x' _Y='y' _Z='count_var';
run;
Upvotes: 3