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

Hi there,

I wonder if someone can help me to figure it out of how to write code for filling the consecutive values, as following:

ID VISIT VALUE WANTS
A 1 0 0
A 2 0 0
A 3 1 1
A 4 0 1
A 5 0 1
B 1 0 0
B 2 0 0
B 3 1 1
B 4 0 1
B 5 0 1

 

for example:

ID A at visit 3, the value = 1, I want to fill the consecutive visits with the value as 1.

 

Please let me know if my question is not clear enough.

Thanks you very much in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

BY-processing is perfect for this type of problem:

 

data want;
retain WANTS;
set have; by ID;
if first.ID then WANTS = 0;
if value then WANTS = 1;
run;

Edited, thanks to ballardw! 

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

BY-processing is perfect for this type of problem:

 

data want;
retain WANTS;
set have; by ID;
if first.ID then WANTS = 0;
if value then WANTS = 1;
run;

Edited, thanks to ballardw! 

PG
ballardw
Super User
If Value then Wants=1;

I think.

 

ursula
Pyrite | Level 9

Thanks, ballardw for updating the code.

I appreciate your help!

ursula
Pyrite | Level 9

wow, it works!!

Thanks so much!!

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
  • 4 replies
  • 1171 views
  • 2 likes
  • 3 in conversation