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).
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!
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.