I have a data set that I need to calculate percentages on.
Sample Table:
Group -------------- Quantity -------------- CumulativeQuantity
A 2 10
A 3 10
A 5 10
etc. 2000+ observations
Want something like this (add a percent variable):
Group -------------- Quantity -------------- CumulativeQuantity-------- Percent
A 2 10 20%
A 3 10 30%
A 5 10 50%
etc./and so on for 2000+ observations
Can't seem to get the code correct to output percent.
Thank you for your help!
Data ds(drop=dummy);
input class1 $ val dummy;
Cards;
A 2 10
A 3 10
A 5 10
;
proc means data=ds nway noprint;
class class1;
var val;
output out=ds_out(drop=_: ) sum(val)=/autoname;
run;
proc sql;
create table x as
select a.*,b.val_sum, a.val/b.val_sum as val_freq format=percent10.2
from ds a,
ds_out b
where a.class1=b.class1;
quit;
Data ds(drop=dummy);
input class1 $ val dummy;
Cards;
A 2 10
A 3 10
A 5 10
;
proc means data=ds nway noprint;
class class1;
var val;
output out=ds_out(drop=_: ) sum(val)=/autoname;
run;
proc sql;
create table x as
select a.*,b.val_sum, a.val/b.val_sum as val_freq format=percent10.2
from ds a,
ds_out b
where a.class1=b.class1;
quit;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.