BookmarkSubscribeRSS Feed
UserSAS7
Calcite | Level 5

Hi all,
For my data, in Proc Report, I am trying to calculate row percentages in an across variable, for grouped data. I am using the following code and for all observations, it is generating right result except for one where only _c2 is 0. I am unable to figure out why it is happening that way.

proc report data= mydata;
columns ('Heading1' label) 
classval,(n pct) ("Mean Rating" varval) ("N" all);
define label / group " ";
define classval / across order=formatted "Rating" format=rating. ;
define n /  "count" ;
define pct / computed  "%"  format=percent9.2;
define varval / mean " " format=8.2;
define all / computed " "  format=8.;
compute pct;
  _c3_ = _c2_ /(_c2_ + _c4_ + _c6_ + _c8_ );
_c5_ = _c4_ /(_c2_ + _c4_ + _c6_ + _c8_ );
_c7_ = _c6_ /(_c2_ + _c4_ + _c6_ + _c8_ );
_c9_ = _c8_ /(_c2_ + _c4_ + _c6_ + _c8_ ); 
endcomp;
compute all;
all = _c2_ + _c4_ + _c6_ + _c8_ ;
endcomp;
run;

Output :
Heading1112233
 count%count%count%count%meanN
observation13735.58%3129.81%2120.19%1514.42%2.13104
observation22120.19%3129.81%3129.81%2120.19%2.5104
observation32019.42%3231.07%3332.04%1817.48%2.48103
observation41211.65%2928.16%4038.83%2221.36%2.7103
observation5001005303903.280
observation698.82%1615.69%5049.02%2726.47%2.93102
observation743.85%2423.08%4139.42%3533.65%3.03104
observation81918.45%2928.16%3130.10%2423.30%2.58103
observation91716.50%2928.16%3433.01%2322.33%2.61103
3 REPLIES 3
UserSAS7
Calcite | Level 5

I reset the options missing=. and used sum() instead of + 
I am getting correct results now.

Thanks for the help!

Kurt_Bremser
Super User
options missing=0;

does not change any values, it only changes how they are displayed. Therefore the simple addition will still result in missing values also, and that's why you need to use the SUM function.

SAS Innovate 2025: Register Now

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!

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
  • 686 views
  • 0 likes
  • 2 in conversation