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

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?

 

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

You got next message in the log:   

NOTE: Variable sex is uninitialized.

I suppose you have to add SEX to COLUMNS staement ?!

ballardw
Super User

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

PaigeMiller
Diamond | Level 26

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!

--
Paige Miller
ballardw
Super User

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2165 views
  • 2 likes
  • 3 in conversation