Hi, I'm trying to create a heat map using spearman correlations, but am getting the following errors when running sgrender:
java.lang.ArrayIndexOutOfBoundsException: 3
ERROR: Physical file does not exist, /tmp/SAS_work50EB00006B2C_localhost.localdomain/_4D29A1B845FFE4BBCA177128127DE4A.bmp.
When I try to run the same code calling for pearson, it works perfectly. Does anyone know why this error occurs when trying to generate the map using spearman and not pearson?
Here is the code I am using:
proc template;
define statgraph corrHeatmap;
dynamic _Title;
begingraph;
entrytitle _Title;
rangeattrmap name='map';
range -1 - 1 / rangecolormodel=(cxfc8d59 cxffffbf cx91bfdb);
endrangeattrmap;
rangeattrvar var=r attrvar=r attrmap='map';
layout overlay /
xaxisopts=(display=(line ticks tickvalues))
yaxisopts=(display=(line ticks tickvalues));
heatmapparm x = x y = y colorresponse = r / xbinaxis=false ybinaxis=false
colormodel=THREECOLORRAMP name = "heatmap" display=all;
continuouslegend "heatmap" /
orient = vertical location = outside title="Spearman Correlation";
endlayout;
endgraph;
end;
run;
%macro prepCorrData(in=,out=);
proc corr data=&in. spearman nocorr
outs=work._tmpCorr
;
run;
data &out.;
keep x y r;
set work._tmpCorr(where=(_TYPE_="CORR"));
array v{*} _numeric_;
x = _NAME_;
do i = dim(v) to 1 by -1;
y = vname(v(i));
r = v(i);
/* creates a diagonally sparse matrix */
if (i<_n_) then
r=.;
output;
end;
run;
proc datasets lib=work nolist nowarn;
delete _tmpcorr;
quit;
%mend;
%prepCorrData(
in=work.one, out=one_heat);
proc sgrender data=one_heat template=corrheatmap;
dynamic _title="Correlation Matrix at 12 Months";
run;
Thank you!
I have the solution in case anyone has this problem in the future (via: Chris Hemedinger of The SAS Dummy):
I found the issue. It's a precision issue with the Spearman output, which sometimes can be so close to 1.0 for self-correlations but can actually be just a tiny bit over 1. That value falls outside of the colormap range that is defined in the GTL code. We can work around with the ROUND function in preparing the matrix for plotting.
Change the DATA step in the "prep data" portion to:
Did the code work before introducing macro language?
I have the solution in case anyone has this problem in the future (via: Chris Hemedinger of The SAS Dummy):
I found the issue. It's a precision issue with the Spearman output, which sometimes can be so close to 1.0 for self-correlations but can actually be just a tiny bit over 1. That value falls outside of the colormap range that is defined in the GTL code. We can work around with the ROUND function in preparing the matrix for plotting.
Change the DATA step in the "prep data" portion to:
data &out.;
keep x y r;
set work._tmpCorr(where=(_TYPE_="CORR"));
array v{*} _numeric_;
x = _NAME_;
do i = dim(v) to 1 by -1;
y = vname(v(i));
/* Round to account for precision differences */
r = round( v(i), 0.0000001 );
/* creates a diagonally sparse matrix */
if (i<_n_) then
r=.;
output;
end;
run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.
data &out.;
keep x y r;
set work._tmpCorr(where=(_TYPE_="CORR"));
array v{*} _numeric_;
x = _NAME_;
do i = dim(v) to 1 by -1;
y = vname(v(i));
/* Round to account for precision differences */
r = round( v(i), 0.0000001 );
/* creates a diagonally sparse matrix */
if (i<_n_) then
r=.;
output;
end;
run;