Here's a simple example of what I am trying to do, using a modified version of SASHELP.CLASS. Note that there are now both a male and female in the class named "Lindsay", and in my PROC REPORT, I want to just highlight the male "Lindsay" but not the female "Lindsay".
So, the problem is: How can I do the test in the COMPUTE block to only highlight the male "Lindsay" since the column SEX is blank for this person?
data class; /* My modified version of SASHELP.CLASS */
set sashelp.class;
if name='Alice' then name='Lindsay';
if name='Jeffrey' then name='Lindsay';
run;
proc report data=class;
columns sex name age height weight;
define sex/group;
compute name;
if sex='M' and name='Alfred' then call define('name','style','style={background=yellow}');
if sex='M' and name='Lindsay' then call define('name','style','style={background=orange}');
endcompute;
run;
You can see that in the output, Alfred has a yellow background, the code works. But the male Lindsay doesn't get an orange background because the value of SEX in a group variable is blank in the table.
It is so interesting question . It is more like a bug .
Using a temp variable to hold SEX value and could get solution.
data class; /* My modified version of SASHELP.CLASS */
set sashelp.class;
if name='Alice' then name='Lindsay';
if name='Jeffrey' then name='Lindsay';
run;
proc report data=class nowd out=temp;
columns sex name age height weight;
define sex/group;
compute before sex;
_s=sex;
endcomp;
compute name;
if _s='M' and name='Alfred' then call define('name','style','style={background=yellow}');
if _s='M' and name='Lindsay' then call define('name','style','style={background=red}');
endcomp;
run;
It is so interesting question . It is more like a bug .
Using a temp variable to hold SEX value and could get solution.
data class; /* My modified version of SASHELP.CLASS */
set sashelp.class;
if name='Alice' then name='Lindsay';
if name='Jeffrey' then name='Lindsay';
run;
proc report data=class nowd out=temp;
columns sex name age height weight;
define sex/group;
compute before sex;
_s=sex;
endcomp;
compute name;
if _s='M' and name='Alfred' then call define('name','style','style={background=yellow}');
if _s='M' and name='Lindsay' then call define('name','style','style={background=red}');
endcomp;
run;
Thanks, @Ksharp . I think I had run into this once before, as your solution looks familiar, but anyway I couldn't figure out how to do this, so now I know.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.