Help using Base SAS procedures

How to add "SUM" words in SUM line in PROC PRINT

Reply
Contributor
Posts: 73

How to add "SUM" words in SUM line in PROC PRINT

Hi all, i have used PROC PRINT to generate a report that i want. So far i managed to get my expected results.

proc print data question.png

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;
Super User
Posts: 6,963

Re: How to add "SUM" words in SUM line in PROC PRINT

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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 73

Re: How to add "SUM" words in SUM line in PROC PRINT

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.

Super User
Posts: 6,963

Re: How to add "SUM" words in SUM line in PROC PRINT

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,260

Re: How to add "SUM" words in SUM line in PROC PRINT

Do SUMLABEL= give what you want?

Data never sleeps
Contributor
Posts: 73

Re: How to add "SUM" words in SUM line in PROC PRINT

it will prompt error whenever i use SUMLBEL = or SUMLABEL

Super User
Posts: 5,260

Re: How to add "SUM" words in SUM line in PROC PRINT

As always when you want help with errors, attach the full log.

Data never sleeps
Super User
Posts: 6,963

Re: How to add "SUM" words in SUM line in PROC PRINT

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,260

Re: How to add "SUM" words in SUM line in PROC PRINT

"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?

Data never sleeps
Super User
Posts: 6,963

Re: How to add "SUM" words in SUM line in PROC PRINT

From his example, I deduce that X_BCAE_POSITION (the column where he wants the "Sum" to be located) is not a BY variable.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,260

Re: How to add "SUM" words in SUM line in PROC PRINT

Oops, missed that Smiley Embarassed

What about GRANDTOTAL_LABEL='label'?

Data never sleeps
Super User
Posts: 6,963

Re: How to add "SUM" words in SUM line in PROC PRINT

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 9,687

Re: How to add "SUM" words in SUM line in PROC PRINT

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;
Contributor
Posts: 73

Re: How to add "SUM" words in SUM line in PROC PRINT

Hey My Xia, you mean after my last PROC PRINT statement?

Super User
Posts: 9,687

Re: How to add "SUM" words in SUM line in PROC PRINT

No. That is another whole different way. 

If you stick with PROC PRINT, then SQL is not for you.

 

 

Ask a Question
Discussion stats
  • 14 replies
  • 672 views
  • 2 likes
  • 4 in conversation