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;
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.