BookmarkSubscribeRSS Feed
inquistive
Quartz | Level 8

Hi Experts,
Scenario:
Dataset(decision) contains following info:

Name      Score     Grade     DecisionMemo
Michael   80           B-            Internship
Michelle  77          C+            Mentoring
Andy       99          A+             Fulbright
Nancy    73           C               Mentoring
Candy   72           C-              Coaching

1.The entire row(s) must be highlighted with a RED background color if the Grade is C(C+, C-), YELLOW if the grade is B(B+, B-), and GREEN if Grade is A(A+, A-).
2.The entire ROW must be highlighted with a PURPLE background color if the Name begins with C(andy), Grade is C- and DecisionMemo is 'Coaching'.

 

This is what I have now:
ods _all_ close;
ods excel file = 'c:\myreport\decision.xlsx';
options (
sheet_name='Memo'
protect_worksheet='on'
autofilter='all'
frozen_headers='on'
orientation='landscape'
screen_resolution_scale_factor='display-scale-factor'
);
proc print data = decision label noobs; run;
style(header)= {just=c foreground=black};
var name  / style(data)={just=l} style(header)={background=light green};

var score / style(data)={just=l} style(header)={background=light green};
var grade / style(data)={just=l} style(header)={background= light brown};
var decisionmemo / style(data)={just=c} style(header)={background= yellow};
ods excel close;

Any relevant links or code (so kind of you, thank you very much!) is greatly appreciated.

 

3 REPLIES 3
Cynthia_sas
SAS Super FREQ

Hi:

  You will need to switch to PROC REPORT if you want to highlight an entire row. For example, consider this output created with ODS EXCEL and PROC REPORT, as shown below:

Cynthia_sas_0-1643581344645.png

There are a few different ways to code the COMPUTE block. I prefer to test a variable on the report row at the end of the row, after all the variables have been placed on the row. PROC REPORT moves from left to right as it is placing items on the report row, so it is easier to do a test on the last item on a row if you want to change the style of the entire row or you want to touch multiple columns on the same row. I make a helper variable called SVAR that holds the style override for each row based on the VALUE of AGE. Note that I defined AGE as a display usage item. If I had taken the default usage of ANALYSIS for AGE, then the IF statement would have needed to change the reference in the IF to AGE.SUM -- but in this case, I was not doing any calculations with AGE or summary lines, so DISPLAY usage allowed me to simplify the IF statement.

 

  PROC PRINT will let you change the color of one variable at a time, but you can't change the color of a whole row in PROC PRINT -- that is one of the examples where PROC REPORT shines.

Cynthia

inquistive
Quartz | Level 8

@cynthia.

Thanks for the quick tip. It seems to work but ignores the following options: 
options (
sheet_name='Memo'
protect_worksheet='on'
autofilter='all'
frozen_headers='on'
orientation='landscape'
screen_resolution_scale_factor='display-scale-factor'
);

 

Is there a way to keep these options in place?

 

PaigeMiller
Diamond | Level 26

You can use these options with PROC REPORT just as you tried earlier with PROC PRINT. These are ODS EXCEL options, not PROC PRINT options.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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