The SAS Output Delivery System and reporting techniques

Accessing BY Group in PROC REPORT COMPUTE Block

Accepted Solution Solved
Reply
Respected Advisor
Posts: 2,054
Accepted Solution

Accessing BY Group in PROC REPORT COMPUTE Block

[ Edited ]

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

Accepted Solutions
Solution
‎08-24-2017 05:56 PM
Super User
Posts: 11,810

Re: Accessing BY Group in PROC REPORT COMPUTE Block

Posted in reply to PaigeMiller

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


All Replies
Trusted Advisor
Posts: 1,633

Re: Accessing BY Group in PROC REPORT COMPUTE Block

Posted in reply to PaigeMiller

You got next message in the log:   

NOTE: Variable sex is uninitialized.

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

Solution
‎08-24-2017 05:56 PM
Super User
Posts: 11,810

Re: Accessing BY Group in PROC REPORT COMPUTE Block

Posted in reply to PaigeMiller

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

Respected Advisor
Posts: 2,054

Re: Accessing BY Group in PROC REPORT COMPUTE Block

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
Super User
Posts: 11,810

Re: Accessing BY Group in PROC REPORT COMPUTE Block

Posted in reply to PaigeMiller

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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