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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.