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?
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;
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;
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.
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;
you added a colon (:) after the sumlabel keyword.
Even I did without Colon Doc, but I am getting same error why?
Post the actual code that you ran.
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;
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;
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?
Sorry, that was not me - it was the user named Sidhu.
I will try both methods and report back!
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
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.