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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.