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

Hi, 

 

I have a dataset called A: 

 

Count | Percent 

0        |  0.05

2        |  0.15

5        |  0.20

...          .....

 

How can I obtain a dataset called B, where Cumulative Percentage for Count = 5 is the Percentage for Count <= 5:

(p(Count = 0) + p(Count = 2) + p(Count = 5) = 0.05 + 0.15 + 0.2 = 0.4) 

 

Count | Perenct | Cumulative Percent

0        |   0.05     |  0.05

2        |   0.15     |  0.20

5        |   0.20     |  0.40

...           ...             ...

 

Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Are you using IML?

 

My assumption is you're looking to calculate the cumulative value?

 

If so, something as simple as:

 

 

retain cum_percent;
cum_percent = sum(cum_percent,  percent);

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

Use the CUSUM function:

 

proc iml;
percent = {0.05, 0.15, 0.2, 0.4, 0.2};
cusum = cusum(percent);
print percent cusum;
Reeza
Super User

Are you using IML?

 

My assumption is you're looking to calculate the cumulative value?

 

If so, something as simple as:

 

 

retain cum_percent;
cum_percent = sum(cum_percent,  percent);
Crubal
Quartz | Level 8

Hi,

 

Any kind of procedure if works would be great! And I just tried yours in a data step, and got what I have. Thanks! 

 

Reeza
Super User

I'm not sure how you're calculating those numbers in the first place, but if using proc freq/means/tabulate you should be able to calculate the cumulative directly.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 4 replies
  • 907 views
  • 3 likes
  • 3 in conversation