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

 How two highlight the Age column  with different colors.

 

 

ods tagsets.excelxp file="bylines.xls" style=statistical

options( suppress_bylines='yes' sheet_interval='none' );

proc report data=sashelp.class nowd;

column name age sex height weight ;

define name / display;

define age / display;

define sex / order;

define height / display;

define weight / display;

 

 

compute AGE;

if (height=50 AND weight<60) then call define(_col_,"style","style={background=blue}");

if (height <60 AND weight >60) then call define(_col_,"style","style={background=red}");

endcomp;

run;

ods _all_ close;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@tekish wrote:
It works fine.
Thanks.

Awesome. Please mark the question solved. 

 

@Cynthia_sas Thanks for the explanation. It's one of those things I know but never remember the details of why 🙂

View solution in original post

5 REPLIES 5
Reeza
Super User

Your first condition is never met with the SASHELP.CLASS dataset.

I don't actually see anything else incorrect with your code...but it doesn't work for me either 😞

Reeza
Super User

It's an order of columns issue. Proc Report has some weird rules about the order of variable usage. If you use the compute weight and explicitly reference the age column it works fine.

 

compute weight;
if height>60 and weight>60 then call define("age", 'style', 'style=[background=blue]');
else if height<60 and weight>60 then call define("age", 'style', 'style=[background=red]'); 
endcomp;
Cynthia_sas
SAS Super FREQ

Good job Reeza! It didn't work in the COMPUTE block for age because PROC REPORT has this "weird" left-to-right rule. In the original COLUMN statement:
column name age sex height weight ;
PROC REPORT builds the report row one cell at a time -- working from the left of the column statement and moving to the right. So at the point in time when PROC REPORT is holding the value of AGE on the report row, it does not yet know the values for HEIGHT or WEIGHT.

So the COMPUTE block for AGE cannot test HEIGHT or WEIGHT. But by the time PROC REPORT is writing WEIGHT on the report row, there is visibility of all the variable values to the "left" of WEIGHT on the report row. So in the COMPUTE block for WEIGHT, all the rest of the variable values can be tested.

cynthia

tekish
Quartz | Level 8
It works fine.
Thanks.
Reeza
Super User

@tekish wrote:
It works fine.
Thanks.

Awesome. Please mark the question solved. 

 

@Cynthia_sas Thanks for the explanation. It's one of those things I know but never remember the details of why 🙂

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5 replies
  • 1600 views
  • 2 likes
  • 3 in conversation