BookmarkSubscribeRSS Feed
vomer
Obsidian | Level 7

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?

14 REPLIES 14
art297
Opal | Level 21

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;

Sidhu
Calcite | Level 5

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;

art297
Opal | Level 21

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.

Sidhu
Calcite | Level 5

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;

Doc_Duke
Rhodochrosite | Level 12

you added a colon (:) after the sumlabel keyword.

Sidhu
Calcite | Level 5

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

art297
Opal | Level 21

Post the actual code that you ran.

TashaChapman
Fluorite | Level 6

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;

Cynthia_sas
SAS Super FREQ

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;

vomer
Obsidian | Level 7

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?

art297
Opal | Level 21

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

vomer
Obsidian | Level 7

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

I will try both methods and report back!

Cynthia_sas
SAS Super FREQ

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

vomer
Obsidian | Level 7

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?

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
  • 7583 views
  • 6 likes
  • 6 in conversation