BookmarkSubscribeRSS Feed
msrenee1984
Obsidian | Level 7

Hello , I wanted to know if there is a way to add column and row totals to my heat map?

 

ods graphics / width=12cm height=50cm;
title "apples eaten Per Facility by Year ";
title2 "apple Counts (N=5952)";
/* basic heat map */
proc sgplot data=freqout; /*temp*/
heatmap x=year y=facility / colorresponse=Count
discretex discretey colormodel=(green redTwoColorRamp)outline ;
yaxis label='Facility Name' valueattrs=(size=4pt) labelattrs=(size=8pt);
xaxis label='Calender Year' valueattrs=(size=5pt) labelattrs=(size=5pt);
text x=year y=facility text=count text=total / textattrs=(size=3pt) ;
run;

1 REPLY 1
MarciaS
SAS Employee

Hi @msrenee1984 

 

You can use the XAXISTABLE and YAXISTABLE statements in PROC SGPLOT to place the row and column totals on the graph.

Below is a sample showing how to do this with your PROC SGPLOT code. 

data freqout; /* Sample data */
  input year facility count;
  datalines;
2021 1 40
2021 2 30
2022 1 10
2022 2 30
2023 1 30
2023 2 40
;
run;
proc sgplot data=freqout noautolegend; /*temp*/
  heatmap x=year y=facility / colorresponse=Count
  discretex discretey colormodel=(green redTwoColorRamp)outline ;
  yaxis label='Facility Name' valueattrs=(size=8pt) labelattrs=(size=8pt);
  xaxis label='Calender Year' valueattrs=(size=8pt) labelattrs=(size=5pt);
  text x=year y=facility text=count / textattrs=(size=8pt) ;
  yaxistable count /position=right valueattrs=(size=8pt) nolabel;
  xaxistable count /position=top valueattrs=(size=8pt) nolabel;
run;

Hope this helps.

 

Regards,

Marcia

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 593 views
  • 0 likes
  • 2 in conversation