BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lnraines
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
lnraines
Fluorite | Level 6

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;

View solution in original post

3 REPLIES 3
ballardw
Super User

Did the code work before introducing macro language?

lnraines
Fluorite | Level 6
I haven't tried the code without the macro, but it works for pearson with
the macro. For example, if I change the output in the proc corr statement
to outp=work._tmpCorr (of course removing nocorr), the heat maps generate
fine. It's only if I try outs= to call the spearman correlations, that I
get these errors.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
lnraines
Fluorite | Level 6

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;

sas-innovate-2024.png

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.

 

Register now!

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
  • 3 replies
  • 1054 views
  • 0 likes
  • 2 in conversation