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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.