I have the following code:
proc print label noobs data=surv1;
var responsec count1 pct1;
sum count1 pct1;
label responsec='Response'
count1='N'
pct1='Pct';
run;
The output looks like this:
Response N Pct
1-Strongly disagree | 11 | 16% |
2-Disagree | 8 | 12% |
3-Neither agree nor disagree | 30 | 44% |
4-Agree | 10 | 15% |
5-Strongly agree | 9 | 13% |
68 | 100% |
---|
Is there a way to add the word "Total" in the last line under "Response"?
Hi:
Look in the PROC PRINT documentation. There is a SUMLABEL= option and a GRANDTOTAL_LABEL= option that can be used. It depends on whether you have BY group processing in the PROC PRINT step or not. Typically, SUMLABEL would be for subgroups and GRANDTOTAL_LABEL would be for the bottom of the report. And if you're not using BY group processing, then you might want to switch to PROC REPORT in order to put some text on the final summary line on the report.
cynthia
Hello Cynthia!
So am I understanding correctly that using proc print, you aren't able to label any sum unless you use a by variable? Thanks!
Hi:
Yes, SUMLABEL is designed for BY groups. But do not despair. PROC REPORT can come to the rescue:
Hope this helps,
Cynthia
ps forgot to snip title statement -- title statement for code was:
title 'Detail Report';
Thank you so much!!
Is there a way to have "Total" print, when the first column is a number or date? The code below doesn't produce total in the summary line. Nothing appears where I would expect the word Total to appear. This same code works though when the first column is a character. Also, I have other examples where the variable is only one or three characters and the word Total gets truncated to 'Tot' or 'T' in those cases. I've tried to format the variable to be six characters hoping it would trick SAS into thinking that the field should be that width, but as you know, there's no tricking SAS.
For example,
proc report data=sasuser.plan_date out=sasuser.plan_daily_all;
column ('ExtendPay Plans by Date' start_date accts transactions Orig_loan Orig_Fees avg_loan avg_fee loan_term) ;
define start_date /group 'Enrollment Date' center;
define accts /n 'Number of Accounts' format=comma15. center;
define transactions /sum ' Number of Transactions' format=comma15. center;
define orig_loan/ sum 'Total Plan Balance' format=dollar15.0;
define orig_fees / sum 'Total Monthly Plan Fees' format=dollar15.0;
define avg_loan /computed'Avg. Plan Amount' format=dollar15.0;
define avg_fee / computed 'Avg. Plan Fees' format=dollar15.0;
define loan_term /mean 'Avg. # of Payments per Plan' center;
where start_date >'31MAR2023'd;
compute avg_loan;
avg_loan=orig_loan.sum/plans.n;
endcomp;
compute avg_fee;
avg_fee=orig_fees.sum/plans.n;
endcomp;
rbreak after / summarize style(summary)=[font=("Calibri")fontweight=bold];
compute after;
START_DATE = 'Total';
endcomp;
run;
Thank you!
Hi:
Instead of tacking a PROC REPORT question onto a 2015 posting about PROC PRINT, it would be better to start a new post, and if you need to, refer to this older post.
You should be seeing a note in your log with your attempt to assign a text string to a numeric variable. I used a subset of SASHELP.CLASS since I did not have your SASUSER data. Here's the default behavior:
However, there are 2 possible methods to do what you want with PROC REPORT, as shown below:
And, yes, summarizing HEIGHT and WEIGHT is sort of silly, but there just needed to be a summary line on the report.
Cynthia
Thank you, @Cynthia_sas. The first option worked.
Hi @AEBatUSB
Honestly I forgot where you should see that option!
I cannot remember the last time I did that "marking a post as a solution".
Keep in mind, The person who originated the post, would be the only one who can mark a post as a solution.
It's not an option on my post, probably since I replied to an old post instead of creating a new one. No worries, it says in my notes that it worked. Both options worked. I ended up having to change it to the second solution because in SAS EG, when I selected Excel as the output for some reason it dropped the word total on the output - I could see it on the HTML output but not on the export. So, I tried the second option Cynthia provided and now the total appears on my output.
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.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.