Reputation: 401
Friends,
In SAS how can we find percentage values of a column?
My data set output and its code is given below
and the code is
data out.calculate_age;
set out.calculate_age ;
if age = "" then age = "All";
if d=. then d=0;
if s=. then s=0;
if i=. then i=0;
tot = d+s+i; /*CALCULATING TOTAL NO. PER GROUP*/
PERCENTAGE=round((tot/sum(tot))*100,.1); /*PERCENTAGE PER GROUP*/
run;
I want, in 'percentage' column, the values should be 8*100/(8+24+36+36+27) , 24*100/(8+24+36+36+27) , 36*100/(8+24+36+36+27) etc... I know sum(tot) is 8/8 , 24/24 etc...(Its calculating row wise)...
So what should I do to get right percentage?
Upvotes: 0
Views: 1858
Reputation: 3576
You could sum up the counts for an overall total and put it into a macro variable:
proc sql ;
select sum(d)+sum(i)+sum(s)
into :N
from input
;quit ;
You can then reference this in your code:
data out.calculate_age;
set out.calculate_age ;
if age = "" then age = "All";
if d=. then d=0;
if s=. then s=0;
if i=. then i=0;
tot = d+s+i; /*CALCULATING TOTAL NO. PER GROUP*/
PERCENTAGE=round(tot/&N.,.1); /*PERCENTAGE PER GROUP*/
run;
Upvotes: 1