BookmarkSubscribeRSS Feed
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

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

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: 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.



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;
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; 

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 = .;
/* merge with observed data */
data Combine;
merge Missing Have;
by ID Day;
/* for consistent results, you might want to sort by the response var */
proc sort data=Combine;
by Diet;

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

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



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4 in conversation