DATA Step, Macro, Functions and more

How to code for the consecutive values

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 92
Accepted Solution

How to code for the consecutive values

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.


Accepted Solutions
Solution
‎09-29-2015 01:17 PM
Esteemed Advisor
Posts: 5,543

Re: How to code for the consecutive values

[ Edited ]

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


All Replies
Solution
‎09-29-2015 01:17 PM
Esteemed Advisor
Posts: 5,543

Re: How to code for the consecutive values

[ Edited ]

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
Super User
Posts: 13,583

Re: How to code for the consecutive values

If Value then Wants=1;

I think.

 

Frequent Contributor
Posts: 92

Re: How to code for the consecutive values

Thanks, ballardw for updating the code.

I appreciate your help!

Frequent Contributor
Posts: 92

Re: How to code for the consecutive values

wow, it works!!

Thanks so much!!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 264 views
  • 2 likes
  • 3 in conversation