Hello,
I have a dataset that has a few observations with the same value for an ID variable, but, for example, one observation has missing values for Variables Atten1-Atten8 but values from Date1-Date8, and another observation that has the same ID has values for Atten1-Atten8, but missing values for Date1-Date8. How can I merge these observations by ID so that data for missing variables in one observation is overwritten by the observation that has non missing data.
Below is an excerpt of my data. Note there shouldn't be discrepancies between observations with the same ID for variables where there is non missing data, such as for the case of ID 2780, Dose. I'll need to investigate and clean that up, so not worried about addressing that.
Any suggestions are much appreciated, thank you!
ID 0713 | Dose 3 | Atten1 1 | Atten2 . | Atten3 . | Atten4 1 | Atten5 . | Atten6 . | Atten7 . | Atten8 . |
0713 | . | . | . | . | . | . | . | . | . |
2780 | 15 | . | 1 | . | . | . | . | 1 | 1 |
2780 | 2 | . | . | . | 1 | . | 1 | . | . |
4176 | . | . | . | . | . | . | . | . | . |
4176 | 10 | . | . | . | . | . | . | . | 1 |
4540 | 7 | . | . | . | . | . | . | . | . |
4540 | . | . | . | . | . | . | . | . | . |
4886 | 3 | . | . | . | . | . | . | . | . |
4886 | . | . | . | . | . | . | . | . | . |
7911 | 1 | . | 1 | . | . | . | . | . | . |
7911 | 2 | . | . | . | . | . | . | . | . |
Thank you, Reeza, for the suggested code and feedback on how to frame questions in a more helpful manner.
The code you shared did exactly what I was looking for - thank you!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.