Statistical programming, matrix languages, and more

How to aggregate value

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 92
Accepted Solution

How to aggregate value

[ Edited ]

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! 


Accepted Solutions
Solution
‎03-16-2017 03:25 PM
Grand Advisor
Posts: 17,338

Re: How to aggregate value

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


All Replies
SAS Super FREQ
Posts: 3,406

Re: How to aggregate value

Use the CUSUM function:

 

proc iml;
percent = {0.05, 0.15, 0.2, 0.4, 0.2};
cusum = cusum(percent);
print percent cusum;
Solution
‎03-16-2017 03:25 PM
Grand Advisor
Posts: 17,338

Re: How to aggregate value

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);
Frequent Contributor
Posts: 92

Re: How to aggregate value

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! 

 

Grand Advisor
Posts: 17,338

Re: How to aggregate value

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 220 views
  • 3 likes
  • 3 in conversation