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

Hello

I want to colour cells if their value exceeds UCL1 or UCL2.

UCL2 is always higher then UCL1.

If cell value exceeds UCL2 then it is red.

If cell value exceeds UCL1 and not UCL2 then it is light pink.

If cell value doesnt exceed UCL1 anddoesnt exceed UCL2 then it is light green.

 

 Why option1 is working well and option2 is not working well?

I don't understand the difference between them in the code

 Data RedLights;
Input Subject UCL1 UCL2 Val2009 Val2006 Val2003 Val1912;
cards;
1 15 20 10 8 9 18
2 13 14 15 10 9 8
3 70 80 50 45 90 30
4 25 35 30 16 15 12
5 30 40 17 20 25 30
;
run;
 

proc report data=RedLights nowd;
  column Subject UCL1 UCL2 Val2009 Val2006 Val2003 Val1912 last;/*Add dummy last*/
  define Subject / display  'Subject/Number';
  define UCL1 / display  "Upper/Control/Limit #1";
  define UCL2 / display  "Upper/Control/Limit #2";
  define Val2009 / display 'SEP-2020' style(column)=[background=lightgreen];
  define Val2006 / display 'JUN-2020' style(column)=[background=lightgreen];
  define Val2003 / display 'MAR-2020' style(column)=[background=lightgreen];
  define Val1912 / display 'DEC-2019' style(column)=[background=lightgreen];
  define last / noprint;

/*Option1*/
/*compute last;*/
/*array aaa val2009 val2006 val2003 val1912;*/
/*do index = 1 to dim (aaa);*/
/*val = aaa(index);*/
/*vname = vname(aaa(index));*/
/*if val <= UCL1 and val<=UCL2 then call define(trim(vname),"style","style={background=lightgreen}");*/
/*else if val>UCL1 and val<=UCL2 then call define(trim(vname),"style","style={background=lightpink}");*/
/*else call define(trim(vname),"style","style={background=red}");*/
/*end;*/
/*endcomp;*/

/*Option2*/
compute last;
array aaa val2009 val2006 val2003 val1912;
do index = 1 to dim (aaa);
val = aaa(index);
vname = vname(aaa(index));
if val <= UCL1 and val<=UCL2 then call define(trim(vname),"style","style={background=lightgreen}");
else if val>UCL1 and val<=UCL2 then call define(trim(vname),"style","style={background=lightpink}");
else if val<=UCL1 and val>UCL2 then call define(trim(vname),"style","style={background=red}");
end;
endcomp;
Run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
shweta_d_singh
Fluorite | Level 6

the last condition looks wrong to me a value can not be greater than and small than at a same time.Check your last condition .

else if val<=UCL1 and val>UCL2 then call define(trim(vname),"style","style={background=red}");

 

 

View solution in original post

1 REPLY 1
shweta_d_singh
Fluorite | Level 6

the last condition looks wrong to me a value can not be greater than and small than at a same time.Check your last condition .

else if val<=UCL1 and val>UCL2 then call define(trim(vname),"style","style={background=red}");

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 572 views
  • 1 like
  • 2 in conversation