BookmarkSubscribeRSS Feed
vegan_renegade
Obsidian | Level 7

Hello, trying to get row totals. I managed to get a total column on the very right, though the numbers across rows are not being summed. Please advise.

 

proc report data=tb_cluster3 nowd
style(header)=[fontsize=6]
style(column)=[fontsize=4]
style(lines)=[fontsize=2];

columns case_status disease_name, started_therapy total;

define started_therapy / "Started Therapy" missing across;
define disease_name / "Disease Name" across;
define case_status / "Case Status" missing group;
define total / "Total" computed;

rbreak after / summarize style(summary)={font_weight=bold};

compute total;
 total=sum(case_status);
endcomp;

compute after;
  call define("case_status", "style", "style=[pretext='Totals']");
endcomp;

run;

table.PNG

 

3 REPLIES 3
ballardw
Super User

Since the values that you want to total are the results of other actions you need to reference the columns that have the values you want.

Instead of

compute total;
 total=sum(case_status);
endcomp;

You might want:

compute total;
 total=sum(_c2_, _c3_ ,_c4_, _c5_,_c6_,_c7_,_c8_,_c9_,_c10_);
endcomp;

Where C2 is the second column, the one to to the right of the CaseStatus. You could select specific columns as you desire 9 columns are shown because of the values of combination of values shown for your disease_name and started_therapy variables. Changes to values mean you need to recount the columns so this is not an automagical result.

vegan_renegade
Obsidian | Level 7
Thank you - I'm not sure how to go about this since disease_name and started_therapy are variables (columns) within my dataset, but the responses to started_therapy (blank, Yes, No, Pending) are not columns, rather responses in the dataset. So I only have two columns to list, not nine.
ballardw
Super User

Show actual data.

Or show report result.

Showing some bizarre mixture of the two does not clarify the situation at all.

Here is an example you should be able to run because the SASHELP.Class data set is typically included in all installs.

proc report data=sashelp.class;
  columns sex age,height total;
  define sex/ group;
  define age/across;
  define total/computed;
  compute total;
     total=sum(_c2_,_c3_,_c4_,_c5_,_c6_,_c7_);
  endcomp;
run;

The row total uses columns 2 through 7 because there are 6 values of age in the Across position.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 5217 views
  • 0 likes
  • 2 in conversation