Hi,
How can I fill in the cohort number for the same record ID but at different time points? Please see
What the dataset looks like:
| Record ID | Timepoint | Cohort # |
| 1 | scr | 1 |
| 1 | bl | . |
| 1 | w8 | . |
| 1 | m6 | . |
| 1 | m12 | . |
| 2 | scr | 1 |
| 2 | bl | . |
| 2 | w8 | . |
| 3 | scr | 2 |
| 3 | bl | . |
| 3 | w8 | . |
What I want:
| Record ID | Timepoint | Cohort # |
| 1 | scr | 1 |
| 1 | bl | 1 |
| 1 | w8 | 1 |
| 1 | m6 | 1 |
| 1 | m12 | 1 |
| 2 | scr | 1 |
| 2 | bl | 1 |
| 2 | w8 | 1 |
| 3 | scr | 2 |
| 3 | bl | 2 |
| 3 | w8 | 2 |
Thank you!
data want;
set have;
by recordid;
retain temp;
if first.recordid then temp=cohort;
if cohort eq . then cohort=temp;
drop temp;
proc print;run;
data want;
set have;
by recordid;
retain temp;
if first.recordid then temp=cohort;
if cohort eq . then cohort=temp;
drop temp;
proc print;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.