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

 

We have used proc sgpanel to create heatmap. Although have used sortorder=descending in the keylegend statement, the legend is not sorted as per the expectation, i.e.  4,3,2,1,0,-1,-2,-3,-4.

I have tried using proc sort with force option to sort the attrmap dataset, but that didn't help either.

Any help/suggestions would be much appreciated.

/* Define attribute map for CHG value colors */
data attrmap;
   length id $20 value 8 fillstyle $10 fillcolor $20;
   id='colormap';
   value=-4; fillstyle='solid'; fillcolor='DELG';     output;
   value=-3; fillstyle='solid'; fillcolor='VILG';     output;
   value=-2; fillstyle='solid'; fillcolor='BILG';     output;
   value=-1; fillstyle='solid'; fillcolor='LIGY';     output; /* brown */
   value= 0; fillstyle='solid'; fillcolor='white';    output;
   value= 1; fillstyle=healmap_legend.PNG'solid'; fillcolor='cxfca5a5'; output;
   value= 2; fillstyle='solid'; fillcolor='cxfb7171'; output;
   value= 3; fillstyle='solid'; fillcolor='RED';      output;
   value= 4; fillstyle='solid'; fillcolor='VIPK';     output;
run;
proc sgpanel data=out.HeatmapF noautolegend dattrmap=attrmap;
    panelby trt_label_sort / sort=descending layout=columnlattice onepanel colheaderpos=top novarname uniscale=row proportional;
    heatmapparm x=ordern y=paramcd_label colorgroup=CHG / attrid=colormap outline discretex discretey;
  keylegend / position=bottom title="Change from Baseline" sortorder=descending ;

    colaxis grid label="Subject" valueattrs=(size=3.5);
    rowaxis min=0 max=200 label="       PART 2                                        PART 1 " reverse;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shain22
Fluorite | Level 6

healmap_legend_2.PNG

Changing sortorder from descending to reverseauto helped:

keylegend / position=bottom title="Change from Baseline" sortorder=reverseauto;


View solution in original post

3 REPLIES 3
DanH_sas
SAS Super FREQ

The easiest way to get what you want here is to add the following following line to your ATTRMAP data step and get rid of the sort option:

 

retain show "attrmap";

 

This will populate the legend with the values from the attributes map -- in the order you listed them.

 

Hope this helps!

Shain22
Fluorite | Level 6

Thanks @DanH_sas. I added the retain statement, but unfortunately still no change in the order on the legend. 

Shain22
Fluorite | Level 6

healmap_legend_2.PNG

Changing sortorder from descending to reverseauto helped:

keylegend / position=bottom title="Change from Baseline" sortorder=reverseauto;


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 249 views
  • 1 like
  • 2 in conversation