Help using Base SAS procedures

SUM on proc print

Reply
Frequent Contributor
Posts: 117

SUM on proc print

Hi all,

I am using a sum function on my proc print statement to get the column total - but I cannot figure out how to get the word "TOTAL" to show beside the total.

Code:

proc print data=testdata noobs label;

   var Org Unit N;

   where Org="Org1";

   sum N;

   label N="Number of x";

   label Org="Organization";

   label unit="Unit";

run;

Ideas on how I can get it to display the word "TOTAL" in the last total row that is generated?

PROC Star
Posts: 7,471

Re: SUM on proc print

Don't know if this is a clean enough solution for you, but it may well be:

data test;

  set sashelp.class;

  retain dummy 1;

run;

proc print data=test noobs sumlabel

   style(grandtotal) = {backgrouncolor=white color=white};

   by dummy;

   sum height weight;

   label  dummy='Total';

   title 'Test of Getting Labeled Total';

run;

Occasional Contributor
Posts: 5

Re: SUM on proc print

Hi Arthur,

Thanks for your answer,I am getting some errors but I tried it by modifying your code little bit.

Even label statement is not working, it displaying as Dummy it self why?

Can you please explain me if you can.

Modified code:

data test;

  set sashelp.class;

  retain dummy 1;

run;

proc print data=test noobs  label

   style(grandtotal) = {background=white};

   by dummy;

   sum height weight;

   label  dummy='Total';

   title 'Test of Getting Labeled Total';

run;

PROC Star
Posts: 7,471

Re: SUM on proc print

You changed the sumlabel option to a label option.  For what you said you wanted to do, I would think that you needed the sumlabel.

Occasional Contributor
Posts: 5

Re: SUM on proc print

Hi Arthur,

Thanks for ur reply, and this was the error I see in my log of using sumlabel.

proc print data=test noobs  sumlabel:

                                 ---------

                                 22      200

ERROR 22-322: Syntax error, expecting one of the following: ;, DATA, DOUBLE, HEADING, LABEL, N,

              NOOBS, OBS, ROUND, ROWS, SPLIT, STYLE, UNIFORM, WIDTH.

ERROR 200-322: The symbol is not recognized and will be ignored.

263     style(grandtotal) = {background=white};

264     by dummy;

265     sum height weight;

266     label  dummy='Total';

267     title 'Test of Getting Labeled Total';

268  run;

Trusted Advisor
Posts: 2,115

Re: SUM on proc print

you added a colon (Smiley Happy after the sumlabel keyword.

Occasional Contributor
Posts: 5

Re: SUM on proc print

Even I did without Colon Doc, but I am getting same error why?

PROC Star
Posts: 7,471

Re: SUM on proc print

Post the actual code that you ran.

Occasional Contributor
Posts: 13

Re: SUM on proc print

You need to have both the LABEL and SUMLABEL options turned on.

Try this.  It almost gets you there, but there's still an extra row for the grand total, even though the font is white...

proc print data=testdata noobs label sumlabel style(grandtotal) = {backgrouncolor=white color=white};

by dummy;

var Org Unit N;

where Org="Org1";

sum N;

label N="Number of x";

label Org="Organization";

label unit="Unit";

label dummy = "Total";

run;

SAS Super FREQ
Posts: 8,864

Re: SUM on proc print

Posted in reply to TashaChapman

Hi:

  Or, instead of struggling with PROC PRINT, you could just switch to PROC REPORT. It's a bit more verbose, but no dummy variable needed.

cynthia

data test;

  set sashelp.class;

  retain dummy 1;

run;

ods html file='c:\temp\_2_ways.html' style=sasweb;

  

options nobyline;

proc print data=test noobs  label sumlabel

   style(grandtotal) = {background=white};

   where name contains "J";

   title 'Art and Tasha Solution with NOBYLINE added';

   by dummy;

   sum height weight;

   label height="Number of x"

         weight='Other Number'

         name="Organization"

         dummy = "Total";

run;

   

proc report data=sashelp.class nowd

      style(summary) = Header;

   where name contains "J";

   title 'PROC REPORT Solution (no "dummy" by group needed)';

   title2 'This solution uses SASHELP.CLASS (not test dataset)';

   column name sex age height weight;

   define name / order 'Organization';

   define sex / display ;

   define age / display;

   define height / sum 'Number of X';

   define weight / sum 'Other Number';

   rbreak after / summarize;

   compute after;

     name = 'Total';

   endcomp;

run;

  

ods _all_ close;

title;

Frequent Contributor
Posts: 117

Re: SUM on proc print

why is there a dummy variable? my original data only has 3 variables: "var Org Unit N;"

does this mean I have to make a dummy var just to be able to show it as total?

PROC Star
Posts: 7,471

Re: SUM on proc print

If you want the totals using proc print, yes, so that you can have a by variable.

You never posted the code that you said failed.

Art

Frequent Contributor
Posts: 117

Re: SUM on proc print

Sorry, that was not me - it was the user named Sidhu.

I will try both methods and report back!

SAS Super FREQ
Posts: 8,864

Re: SUM on proc print

And, if you switch to PROC REPORT, as shown in my code, then you do NOT need a dummy variable. If you notice, my PROC REPORT code works with SASHELP.CLASS directly. As Art said, since you did not post any data, I used SASHELP.CLASS to illustrate my example,

cynthia

Frequent Contributor
Posts: 117

Re: SUM on proc print

Posted in reply to Cynthia_sas

Hi Cynthia, I tried your method and does not seem to give me the word "total" at the last row:

proc report data=dataset nowd

style(summary) = Header;

  where Sender='Site1';

  column Sender unit N UniqueClients;

  define Sender / order 'Sending Organization';

  define unit / order 'Unit';

  define N / sum 'Number of X';

  define UniqueClients / sum 'Number of Y';

  rbreak after / summarize;

   compute after;

     name = 'Total';

   endcomp;

run;

What am I doing wrong?

Ask a Question
Discussion stats
  • 14 replies
  • 1617 views
  • 6 likes
  • 6 in conversation