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

Hi I want to use WOCF for my dataset but How can you do that.  so I have two dataset code which one i have and what i want. please help me I tried Lag but didn't succeed.

 

data have;
input id $ visitnum aval ;
datalines;
1 1 0
1 2 3
1 3 3
1 4 4
1 5 3
1 6 3
1 7 3
1 8 4
1 9 4
;
run;


data want;
input id $ visitnum aval dtype ;
datalines;
1 1 0
1 2 3
1 3 3
1 4 4
1 5 4 WOCF
1 6 4 WOCF
1 7 4 WOCF
1 8 4
1 9 4
;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Reeza
Super User
What is WOCF?
Worst observation carried forward?
dpa
Obsidian | Level 7 dpa
Obsidian | Level 7
yes
Reeza
Super User
Lag or DIF or RETAIN are options. Show the code you tried with Lag please.
dpa
Obsidian | Level 7 dpa
Obsidian | Level 7

with Lag function I only manqged to change next one but i don't know how to do that with other two .

Kurt_Bremser
Super User
retain _aval;
if first.id then _aval = aval;
if aval lt _aval
then do;
  aval = _aval;
  dtype = 'WOCF';
end;
else _aval = aval;
drop _aval;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3916 views
  • 0 likes
  • 3 in conversation