aggreagte function for each row going backwards in date

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

aggreagte function for each row going backwards in date

Hi all,

Can any one help me out with the following?

i want to get max(cnt) by date upto that particular date. For example i want my result dataset to be like below.

datalines;

date               cnt

23march2013 10

24march2013 25

14april2013 15

15april2013 30

18april2013 17

result dataset:

date max(cnt)

23march2013 10

24march2013 25

14april2013 25

15april2013 30

18april2013 30

Thanks in advance,

RK


Accepted Solutions
Solution
‎11-12-2013 11:29 AM
Super User
Posts: 17,784

Re: aggreagte function for each row going backwards in date

Look up the retain statement.

You want to retain the variable and if the CNT is larger then change it to the new maximum.

data want;

set have;

retain max_cnt 0;

if cnt>max_cnt then max_cnt=cnt;

run;

View solution in original post


All Replies
Solution
‎11-12-2013 11:29 AM
Super User
Posts: 17,784

Re: aggreagte function for each row going backwards in date

Look up the retain statement.

You want to retain the variable and if the CNT is larger then change it to the new maximum.

data want;

set have;

retain max_cnt 0;

if cnt>max_cnt then max_cnt=cnt;

run;

Super User
Posts: 5,255

Re: aggreagte function for each row going backwards in date

Just retain a new variable max_cnt, and do max_cnt = max(max_cnt,cnt).

Data never sleeps
☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 153 views
  • 3 likes
  • 3 in conversation