BookmarkSubscribeRSS Feed
Giftable
Calcite | Level 5
Hi all. I have a data set, with 3 variables
ID Diet Day
1 0 0
1 0 2
1 1 3
2 1 1
3 0 1
4 1 0
5 0 2
5 2 2

My diet variable means a person (ID) could have had Diet 1 on a given day, but also a mix of 1 and 2 (i.e. 2) on a given day. I have generated a heatmap to visualise this, but as you can see the day variable is different for all IDs. Some IDs have observations for day 0 and some only for day 2. So when I generate my heatmap (proc sgplot with the heatmap and coulourgroup=), I see the white gaps inbetween. I am looking for a way in which I can assign a colour to those white spaces inbetween the tiles in SAS. For example I was ro assigna colour to a white space in which ID 5 has not data for day 0. I could appreciate any help
3 REPLIES 3
sbxkoenk
SAS Super FREQ

[  I have moved this post to 'Graphics Programming' board.  ]

ballardw
Super User

Show the code you are using for your heatmap. Since there enough options involved I don't want to spend time trying to guess which approach you started with. The options you have chosen may well influence other options needed.

 

A description of what color you want where may help as well. There are multiple ways to assign colors

 

Example data that will run your heatmap would be a good idea. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the <> icon or attached as text to show exactly what you have and that we can test code against.

 

Rick_SAS
SAS Super FREQ

Well, WHITE is a color, but I guess you are saying you want a non-white color for the missing cells.

 

I assume your current program looks like the following. Notice that I am using the HEATMAPPARM statement, which assumes the data are presummarized:

data Have;
input ID Diet Day;
datalines;
1 0 0
1 0 2
1 1 3
2 1 1
3 0 1
4 1 0
5 0 2
5 2 3
;
title "A Heat Map";
proc sgplot data=Have;
heatmapparm x=Day y=ID colorgroup=Diet; 
run;

To add color to the missing cells, you need to explicitly add the coordinates of the cells and use a missing value for the DIET variable. THe following code creates a grid of missing values and then merges the data with the grid so that your observed values overwrite the missing values:

 

/* create grid of missing values */
data Missing;
do ID = 1 to 5;
   do Day = 0 to 3;
      Diet = .;
      output;
   end;
end;
run;
/* merge with observed data */
data Combine;
merge Missing Have;
by ID Day;
run;
/* for consistent results, you might want to sort by the response var */
proc sort data=Combine;
by Diet;
run;

title "A Heat Map";
proc sgplot data=Combine;
heatmapparm x=Day y=ID colorgroup=Diet / outline; 
keylegend;
run;

The color of the missing cells is the GraphMissing style element in the current ODS style.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3 replies
  • 994 views
  • 0 likes
  • 4 in conversation