🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-17-2020 04:01 AM
(1189 views)
Hi, I have a variable X with the sequence of number such as: 3, 4, 6, 5, 4, 7, 9, 7, 8, 9, 10. I need to create a new variable Y so that Yi=max(Xi, Yi-1). It would become a sequence like: 3, 4, 6, 6, 6, 7, 9, 9, 9, 9, 10. How can I do the programming to get this new variable? Thank you so much for your suggestion.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @hansmuller
I am thinking about something like this, using the RETAIN function:
data want;
set have;
retain y;
if x >= y then y=x;
run;
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @hansmuller,
Apply the RETAIN statement to y:
data have;
infile cards dsd;
input x @@;
cards;
3, 4, 6, 5, 4, 7, 9, 7, 8, 9, 10
;
data want;
set have;
y=max(x,y);
retain y;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @hansmuller
I am thinking about something like this, using the RETAIN function:
data want;
set have;
retain y;
if x >= y then y=x;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Alternatively with ifn and retain
data want;
set have;
retain new;
new=ifn(x<new,new,x);
run;
Thanks,
Jag
Jag