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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.