BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

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.

 

Capture.PNG

 

 

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

Ksharp_0-1624368216366.png

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

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;

Ksharp_0-1624368216366.png

 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
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
  • 2 replies
  • 1056 views
  • 1 like
  • 2 in conversation