Help using Base SAS procedures

How Can I Put The Correct Value in a Line Statment for a Compute Before

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

How Can I Put The Correct Value in a Line Statment for a Compute Before

In a PROC REPORT I figured out how to insert a sub-title row before a new group begins, but I cannot figure out out to get the correct group name into the sub-title.

 

Notice that in my output :

  • 1st sub-title text is 'Make:'
  • 2nd sub-title is 'Make: Chevy'

It is supposed to be

  • 1st sub-title should be 'Make: Chevy'
  • 2nd sub-title should be  'Make: Ford'

My code is below, screen shot of output is attached.

 

Here is the code to create data for this example:

data cars;
	infile datalines dlm=',';
	input makeNum make:$12. _BREAK_:$25. description:$50. retail myCost;
	datalines;
	1,Chevy, , Chevy-Impala-Red, 32000, 29000
	1,Chevy, , Chevy-Impala-Blue,32000, 29500
	1,Chevy,makeModel, Total: Chevy-Impala, 64000, 58500
	1,Chevy, , Chevy-Malibu-White, 28000, 26500
	1,Chevy,makeModel, Total: Chevy-Malibu, 28000, 26500
	1,Chevy,make, Total: Chevy,92000, 85000
	2,Ford, ,Ford-Fiesta-Silver,14000,12000
	2,Ford, ,Ford-Fiesta-Blue,14000,12000
	2,Ford,, ,Ford-Fiesta-Gold,14500,12000
	2,Ford,makeModel, Total: FordFiesta, 42500,36000
	2,Ford, ,Ford-Focus-Silver, 17000, 16000
	2,Ford, ,Ford-Focus-Blue,1700,15800
	2,Ford,makeModel, Total: Ford-Focus,34000,31800
	2,Ford,make, Total: Ford, 76500,67800
	, , _RBREAK_, TOTAL: ,168500,152800
	;
run;

 

Here is my code for the report:

TITLE1 "List Report";
FOOTNOTE1 "Generated by the SAS System (&_SASSERVERNAME, &SYSSCPL) on %TRIM(%QSYSFUNC(DATE(), NLDATE20.)) at %TRIM(%SYSFUNC(TIME(), TIMEAMPM12.))";

proc report data=WORK.CARS nowd;
	column makeNum  make  _BREAK_ description retail  myCost;
	define makeNum /  group missing order=data noprint;	
	define make /group missing  order=data noprint;
	compute  make;
		if make ne ' ' then hold1=make;
		if make eq ' ' then make=hold1;
	endcomp;
	define _BREAK_ / display '_BREAK_' missing order=data noprint;
	define description / display 'description' missing order=data;
	define retail / display missing  order=data;
	define myCost / display missing  order=data;

	compute _BREAK_;
		if _BREAK_ ne ' ' then do;
			call define(_ROW_,'style','style=[font_weight=bold foreground=Black paddingbottom=10]');
		end;
	endcomp;

	 COMPUTE Before makeNum;                                                               
      LENGTH text $ 50;                                                                
      IF makeNum > 0 THEN DO;                                                                   
		text = cat('Make: ', make); 
         num=50;                                                                       
      END;                                                                             
      ELSE DO;                                                                         
         text = "";                                                                    
         num=0;                                                                        
      END;                                                                             
      LINE text $VARYING. num ; 
   ENDCOMP;                      


run;

quit;

TITLE;
FOOTNOTE;

2017-04-21_11-04-00.jpg

Accepted Solutions
Solution
‎04-21-2017 11:30 PM
SAS Super FREQ
Posts: 8,869

Re: How Can I Put The Correct Value in a Line Statment for a Compute Before

[ Edited ]
Posted in reply to thomp7050

And my guess is that it's not working because you are trying to use MAKE in the COMPUTE block for MAKENUM. But at the point in time when PROC REPORT is handling MAKENUM, it has not yet put MAKE onto the report row. Remember that PROC REPORT does not have a PDV like the DATA step program.

I am thinking that if you changed
COMPUTE BEFORE MAKENUM;
to
COMPUTE BEFORE MAKE;

It would probably work. It did for me.

drove_my_chevy.png

 

But I have to second what others have said, it seems silly to read the summarized CSV results from a previous PROC REPORT step, when you could easily have had PROC REPORT generate the report for you in the first place.

And you might want to pay attention to the note in the log about the usage of GROUP not being appropriate here anymore because _BREAK_ in this context is a DISPLAY item and so GROUP won't work.

cynthia

View solution in original post


All Replies
Super User
Posts: 11,343

Re: How Can I Put The Correct Value in a Line Statment for a Compute Before

Posted in reply to eg_michael

Why did you make the data in the data set have the summary values? The breaks in proc report are to help manage summary totals.

 

Just looking at your data I would be more likely to structure the data with Make, Model, Color, retail and cost and let breaks on make and model do the summaries.

Occasional Contributor
Posts: 9

Re: How Can I Put The Correct Value in a Line Statment for a Compute Before

This is a unique situation, I am creating a report from the output of another report.
Frequent Contributor
Posts: 93

Re: How Can I Put The Correct Value in a Line Statment for a Compute Before

Posted in reply to eg_michael

Unfortunately it is a little difficult to execute with your posted code, given that line structure is important in datalines command.  Could you repost with the datalines restructured?

Solution
‎04-21-2017 11:30 PM
SAS Super FREQ
Posts: 8,869

Re: How Can I Put The Correct Value in a Line Statment for a Compute Before

[ Edited ]
Posted in reply to thomp7050

And my guess is that it's not working because you are trying to use MAKE in the COMPUTE block for MAKENUM. But at the point in time when PROC REPORT is handling MAKENUM, it has not yet put MAKE onto the report row. Remember that PROC REPORT does not have a PDV like the DATA step program.

I am thinking that if you changed
COMPUTE BEFORE MAKENUM;
to
COMPUTE BEFORE MAKE;

It would probably work. It did for me.

drove_my_chevy.png

 

But I have to second what others have said, it seems silly to read the summarized CSV results from a previous PROC REPORT step, when you could easily have had PROC REPORT generate the report for you in the first place.

And you might want to pay attention to the note in the log about the usage of GROUP not being appropriate here anymore because _BREAK_ in this context is a DISPLAY item and so GROUP won't work.

cynthia

Occasional Contributor
Posts: 9

Re: How Can I Put The Correct Value in a Line Statment for a Compute Before

Posted in reply to Cynthia_sas

Thank you Cynthia, it worked for me too! 

Thank you everyone for your critique and advice. I have noted it all.Smiley Happy

 

Michael

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 185 views
  • 1 like
  • 4 in conversation