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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 467 views
  • 1 like
  • 2 in conversation