Here's what I'm trying to do in a very simplified example. For my PROC REPORT output, I want some columns of my output to be in italic if the BY group variable is a certain value, and otherwise not in italic. But the way I am doing it, it doesn't work, no italics appear and there is a message in the log. Code:
proc sort data=sashelp.class out=class; by sex; run; ods_html; proc report data=class; by sex; columns name height weight; define name/group; compute height; if sex='F' then call define('_c2_',"style","style=[fontstyle=italic]"); endcompute; run; ods html close;
Log:
1433 proc report data=class; 1434 by sex; 1435 columns name height weight; 1436 define name/group; 1437 compute height; 1438 if sex='F' then call define('_c2_',"style","style=[fontstyle=italic]"); 1439 endcompute; 1440 run; NOTE: Variable sex is uninitialized. NOTE: The above message was for the following BY group: Sex=F NOTE: Variable sex is uninitialized. NOTE: The above message was for the following BY group: Sex=M NOTE: There were 19 observations read from the data set WORK.CLASS. NOTE: PROCEDURE REPORT used (Total process time): real time 0.04 seconds cpu time 0.03 seconds 1441 ods html close;
Can this work? How can I reference the BY variable in the COMPUTE block?
Proc report requires that any variable referenced in a calculation be to the left of the position it is being refenced. So you will want to add SEX to columns, left height. Set the option NOPRINT for SEX in a define block.
Such as
define sex /display noprint;
And you be a bit closer to your goal
You got next message in the log:
NOTE: Variable sex is uninitialized.
I suppose you have to add SEX to COLUMNS staement ?!
Proc report requires that any variable referenced in a calculation be to the left of the position it is being refenced. So you will want to add SEX to columns, left height. Set the option NOPRINT for SEX in a define block.
Such as
define sex /display noprint;
And you be a bit closer to your goal
Well, duh, I knew that but for some reason, I didn't think it applied to BY variables.
However, the code does what I want now. Thanks!
@PaigeMiller wrote:
Well, duh, I knew that but for some reason, I didn't think it applied to BY variables.
However, the code does what I want now. Thanks!
I swear that I have absolutely, never ever had to say "I knew that but ..." about my code. Honest. Really.
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!
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.