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.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.