BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Garzaluis998
Calcite | Level 5

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10
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;

View solution in original post

1 REPLY 1
smantha
Lapis Lazuli | Level 10
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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 1 reply
  • 1839 views
  • 0 likes
  • 2 in conversation