BookmarkSubscribeRSS Feed
tburus
Obsidian | Level 7

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:

plot.png

3 REPLIES 3
s_lassen
Meteorite | Level 14

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;
Tom
Super User Tom
Super User

I don't think you can reference columns to the right of the place you are doing the calculations.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 987 views
  • 0 likes
  • 3 in conversation