Hi all, i have used PROC PRINT to generate a report that i want. So far i managed to get my expected results.
aaa
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;
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;
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.
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.
Do SUMLABEL= give what you want?
it will prompt error whenever i use SUMLBEL = or SUMLABEL
As always when you want help with errors, attach the full log.
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.
"SUMLABEL='label'
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?
From his example, I deduce that X_BCAE_POSITION (the column where he wants the "Sum" to be located) is not a BY variable.
Oops, missed that
What about GRANDTOTAL_LABEL='label'?
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.
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;
Hey My Xia, you mean after my last PROC PRINT statement?
No. That is another whole different way.
If you stick with PROC PRINT, then SQL is not for you.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.