BookmarkSubscribeRSS Feed
imdickson
Quartz | Level 8

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;
14 REPLIES 14
Kurt_Bremser
Super User

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;
imdickson
Quartz | Level 8

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.

Kurt_Bremser
Super User

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.

LinusH
Tourmaline | Level 20

Do SUMLABEL= give what you want?

Data never sleeps
imdickson
Quartz | Level 8

it will prompt error whenever i use SUMLBEL = or SUMLABEL

LinusH
Tourmaline | Level 20

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

Data never sleeps
Kurt_Bremser
Super User

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.

LinusH
Tourmaline | Level 20

"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
LinusH
Tourmaline | Level 20

Oops, missed that Smiley Embarassed

What about GRANDTOTAL_LABEL='label'?

Data never sleeps
Kurt_Bremser
Super User

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.

Ksharp
Super User

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;
imdickson
Quartz | Level 8

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

Ksharp
Super User

No. That is another whole different way. 

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 14 replies
  • 2312 views
  • 2 likes
  • 4 in conversation