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.
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!
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!
If Value then Wants=1;
I think.
Thanks, ballardw for updating the code.
I appreciate your help!
wow, it works!!
Thanks so much!!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.