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.
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.