BookmarkSubscribeRSS Feed
Roberta324
Calcite | Level 5

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 disagree1116%
2-Disagree812%
3-Neither agree nor disagree3044%
4-Agree1015%
5-Strongly agree913%
  68100%

Is there a way to add the word "Total" in the last line under "Response"?

12 REPLIES 12
Cynthia_sas
SAS Super FREQ


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

tanner_lund
Calcite | Level 5

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!

Cynthia_sas
SAS Super FREQ

Hi:

  Yes, SUMLABEL is designed for BY groups. But do not despair. PROC REPORT can come to the rescue:

label_total_procreport.png

Hope this helps,

Cynthia

 

ps forgot to snip title statement -- title statement for code was:

title 'Detail Report';

AEBatUSB
Fluorite | Level 6

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!

Cynthia_sas
SAS Super FREQ

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:

Cynthia_sas_0-1682543161302.png

 

  However, there are 2 possible methods to do what you want with PROC REPORT, as shown below:

Cynthia_sas_1-1682544045979.png

And, yes, summarizing HEIGHT and WEIGHT is sort of silly, but there just needed to be a summary line on the report.

Cynthia

AEBatUSB
Fluorite | Level 6

Thank you, @Cynthia_sas.  The first option worked.

AhmedAl_Attar
Rhodochrosite | Level 12
@AEBatUSB
You'll need to mark/accept the post that worked as a solution
AEBatUSB
Fluorite | Level 6
HI AhmedAl_Attar,
I don’t see a place for me to do that.
AhmedAl_Attar
Rhodochrosite | Level 12

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.

AEBatUSB
Fluorite | Level 6

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. 

AhmedAl_Attar
Rhodochrosite | Level 12
I found it!
Go here https://communities.sas.com/t5/help/faqpage/title/solution_howdoi
and look for "How do I mark a message as a solution?" within/under "Accepted Solutions"

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!

How to Concatenate Values

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.

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
  • 12 replies
  • 2991 views
  • 3 likes
  • 5 in conversation