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 :
It is supposed to be
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;
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.
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
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.
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?
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.
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
Thank you Cynthia, it worked for me too!
Thank you everyone for your critique and advice. I have noted it all.
Michael
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.