03-14-2016 04:24 AM
Hi all, i have used PROC PRINT to generate a report that i want. So far i managed to get my expected results.
As you can see, i got a SUM after the last row. What i want now is to add the word "SUM" below "Java Programmer". Is there a way to do so? My code is as below:
proc print data=WORK.JOIN2BCAE obs='No.' label; title 'Alfred Employee Bank Commitment/Financial Status'; var X_BCAE_NAME X_BCAE_POSITION X_BCAE_INCOME X_BCAE_CARLOAN X_BCAE_MORTGAGE X_BCAE_CASHFLOW newsum; label X_BCAE_NAME = 'Name' X_BCAE_POSITION = 'Position' X_BCAE_INCOME = 'Income' X_BCAE_CARLOAN = 'Car Loan Installment' X_BCAE_MORTGAGE = 'Mortgage' X_BCAE_CASHFLOW = 'Cash Flow' newsum = 'Maximum New Loan'; sum X_BCAE_INCOME X_BCAE_CARLOAN X_BCAE_MORTGAGE X_BCAE_CASHFLOW newsum; RUN;
03-14-2016 05:31 AM
PROC PRINT is a very simple procedure with minimal features. You can't do more with SUM than you already did.
I recommend you take a look at the REPORT procedure for more flexible report creation.
There you can set values for columns in a compute block for the time when a group switch occurs:
define X_BCAE_POSITION / display 'Position'; compute X_BCAE_POSITION; if _break_='RBREAK' then do; call define("X_BCAE_POSITION", 'style', 'style=[pretext="Sum"]'); end; endcomp;
You can use the Wizard in Enterprise Guide to get the basic code for the PROC REPORT step and then experiment with manipulating the summary line
This is sample code for SASHELP.CLASS:
proc report data=SASHELP.CLASS nowd; column Name Sex Age, SUM=Age_SUM Height, SUM=Height_SUM Weight, SUM=Weight_SUM; define Name / group 'Name' missing; compute Name; if _break_ eq ' ' then do; if Name ne ' ' then hold1=Name; end; if upcase(_break_)="NAME" then do; call define("Name", 'style', 'style=[pretext="Zwischensumme "]'); end; endcomp; define Sex / display 'Sex' missing; compute Sex; if _break_ eq ' ' then do; if Sex ne ' ' then hold2=Sex; end; if _break_='_RBREAK_' then do; call define("Sex", 'style', 'style=[pretext="Sum"]'); end; endcomp; define Age / analysis SUM 'Age' missing; define Height / analysis SUM 'Height' missing; define Weight / analysis SUM 'Weight' missing; rbreak after / summarize; run; quit;
03-14-2016 05:36 AM
Thx for the advice. Will look into PROC REPORT but as for this moment, PROC REPORT is quite confusing for me....It is not as easy as you may think for me.....think i will need a lot more time to further research on this topic.
03-14-2016 05:39 AM
It is also very confusing for me, as I'm more of a data architect than report creator, so I rarely get to tinker with it.
All I did was create a report with the wizard in EG and then play around with the statements in the compute block until I got the desired result.
So you see, even for seasoned SAS users the helpers in EG can be very convenient at times.
03-14-2016 06:57 AM
I don't think that SUMLABEL does what he wants. SUMLABEL only causes the Label of the BY variable to be displayed in the summary line (instead of the simple variable name).
Since he wants to display some arbitrary text in a column of a non-BY variable, this won't help.
03-14-2016 07:05 AM
specifies the text to use as a label on the summary line of a BY group. You can include the #BYVAR and #BYVAL variables in 'label'."
I think this will cover the OPs requirement, no?
03-14-2016 07:10 AM
From his example, I deduce that X_BCAE_POSITION (the column where he wants the "Sum" to be located) is not a BY variable.
03-14-2016 10:32 AM
Ah, I see that's new with 9.4. If the OP is at an earlier release, this may be the cause for the ERRORs.
I still don't think it gives one the necessary freedom in selecting where (which column) to put the labels. That's why PROC REPORT may be the (only) way to go.
03-14-2016 10:27 PM
This could be easy done by SQL.
proc sql; select name label='xxxxx', sex ,weight ,height from sashelp.class union all select ' ','Sum:',sum(weight ),sum(height) from sashelp.class; quit;