Hi all!
I would like to duplicate a value within 1 individual. See below for my example.
In my example, I have multiple rows per individual, however only on 1 row contains a value for the Swabdate variable. I would like to duplicate this value to all rows within the individual.
How can I do this? Thank you so much!
Example:
Obs | study_id | swabdate |
1 | ~11001~ | . |
2 | ~11001~ | . |
3 | ~11001~ | . |
4 | ~11001~ | . |
5 | ~11001~ | . |
6 | ~11001~ | . |
7 | ~11001~ | . |
8 | ~11001~ | . |
9 | ~11001~ | . |
10 | ~11001~ | . |
11 | ~11001~ | . |
12 | ~11001~ | 09/08/2017 |
13 | ~11003~ | . |
14 | ~11003~ | . |
15 | ~11003~ | . |
16 | ~11003~ | . |
17 | ~11003~ | . |
18 | ~11003~ | . |
19 | ~11003~ | . |
20 | ~11003~ | . |
21 | ~11003~ | . |
22 | ~11003~ | 09/18/2017 |
23 | ~11005~ | . |
A datastep solution:
/* Assuming data is sorted by study_id */
data want;
do until(last.study_id);
set have; by study_id;
newdate = coalesce(newdate, swabdate);
end;
do until(last.study_id);
set have; by study_id;
output;
end;
format newdate mmddyy10.;
drop swabdate;
rename newdate=swabdate;
run;
Note: This pics up the first non-missing date encountered. To get the last date, use:
coalesce( swabdate, newdate).
A datastep solution:
/* Assuming data is sorted by study_id */
data want;
do until(last.study_id);
set have; by study_id;
newdate = coalesce(newdate, swabdate);
end;
do until(last.study_id);
set have; by study_id;
output;
end;
format newdate mmddyy10.;
drop swabdate;
rename newdate=swabdate;
run;
Note: This pics up the first non-missing date encountered. To get the last date, use:
coalesce( swabdate, newdate).
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.