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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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