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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

5 REPLIES 5
ballardw
Super User

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.

eg_michael
Fluorite | Level 6
This is a unique situation, I am creating a report from the output of another report.
thomp7050
Pyrite | Level 9

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?

Cynthia_sas
SAS Super FREQ

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

eg_michael
Fluorite | Level 6

Thank you Cynthia, it worked for me too! 

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

 

Michael

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1105 views
  • 1 like
  • 4 in conversation