I am trying to create a table with PROC REPORT that includes a summary line using RBREAK. I expected this line would summarize the computed variables, but it is not. Please advise. (Note: my pct. format just add the percent sign to 0 and is percent8.1 otherwise.)
proc report data=all_t2a nowd split="*"
style(report)=[frame=hsides rules=none]
style(header)=[background=white color=&rgreen. borderbottomcolor=black]
style(lines)=[background=white];
column sport_name tl2,(tot pct) ('Total' all all_pct);
define sport_name / group '' center order=data format=$sport_cap. style(column)=[cellwidth=2in just=l] style(header)=[just=l];
define tl2 / across '' order=data format=$tl_form.;
define tot / analysis SUM 'n' format=comma8.0 style(column)=[cellwidth=0.75in just=c];
define pct / computed "%" format=pct.;
define all / computed "n" format=comma8.0;
define all_pct / computed '%' f=pct.;
/* Sum total number of responses to question */
compute before sport_name;
den = _c2_ + _c4_ + _c6_;
endcomp;
/* Calculate percentage */
compute pct;
_c3_ = _c2_ / den;
_c5_ = _c4_ / den;
_c7_ = _c6_ / den;
endcomp;
compute all;
all = _c2_ + _c4_ + _c6_;
endcomp;
compute all_pct;
all_pct = all / all;
endcomp;
rbreak before /summarize style(summary)={font_weight=bold};
compute sport_name;
if _break_ = '_RBREAK_' then sport_name = 'Overall';
endcomp;
run;
Result:
I think the problem is with having the denominator in a separate compute statement, and there is no need to, AFAIK.
So this may work:
proc report data=all_t2a nowd split="*"
style(report)=[frame=hsides rules=none]
style(header)=[background=white color=&rgreen. borderbottomcolor=black]
style(lines)=[background=white];
column sport_name tl2,(tot pct) ('Total' all all_pct);
define sport_name / group '' center order=data format=$sport_cap. style(column)=[cellwidth=2in just=l] style(header)=[just=l];
define tl2 / across '' order=data format=$tl_form.;
define tot / analysis SUM 'n' format=comma8.0 style(column)=[cellwidth=0.75in just=c];
define pct / computed "%" format=pct.;
define all / computed "n" format=comma8.0;
define all_pct / computed '%' f=pct.;
/* Calculate percentage */
compute pct;
/* Sum total number of responses to question */
den = _c2_ + _c4_ + _c6_;
_c3_ = _c2_ / den;
_c5_ = _c4_ / den;
_c7_ = _c6_ / den;
endcomp;
compute all;
all = _c2_ + _c4_ + _c6_;
endcomp;
compute all_pct;
all_pct = all / all;
endcomp;
rbreak before /summarize style(summary)={font_weight=bold};
compute sport_name;
if _break_ = '_RBREAK_' then sport_name = 'Overall';
endcomp;
run;
I don't think you can reference columns to the right of the place you are doing the calculations.
Have you tried?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.