Hi Everyone,
I'm trying to carry a visit date across all rows of each participant ID, to create a start date column. I've used the below code to carry values across IDs in other coding, but now it just keeps telling me that _id is uninitialized. Is there something I'm missing? Is there a better way to do this?
Code:
data TOSStart(drop=_:);
do until (last.id);
set toscount;
by id;
if id > _id then do;
_Start = Start;
end;
end;
do until (last.id);
set toscount;
by id;
Start = _Start;
output;
end;
run;
Have this:
ID | Start |
1 | 1/1/2022 |
1 | |
1 | |
1 | |
4 | 3/5/2022 |
4 | |
4 | |
6 | 2/8/2022 |
6 | |
6 | |
6 | |
6 | |
6 | |
6 |
Want this:
ID | Start |
1 | 1/1/2022 |
1 | 1/1/2022 |
1 | 1/1/2022 |
1 | 1/1/2022 |
4 | 3/5/2022 |
4 | 3/5/2022 |
4 | 3/5/2022 |
6 | 2/8/2022 |
6 | 2/8/2022 |
6 | 2/8/2022 |
6 | 2/8/2022 |
6 | 2/8/2022 |
6 | 2/8/2022 |
6 | 2/8/2022 |
Thanks!
Do this:
data TOSStart (drop=_:);
set toscount (rename=(start=_start));
by id;
retain start;
format start mmddyy10.;
if first.id then start = _start;
run;
Do this:
data TOSStart (drop=_:);
set toscount (rename=(start=_start));
by id;
retain start;
format start mmddyy10.;
if first.id then start = _start;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.