BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JackHP
Fluorite | Level 6

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.........
278015.1....11
27802...1.1..
4176.........
417610.......1
45407........
4540.........
48863........
4886.........
79111.1......
79112........
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
You should show what you want as output but usually this works for what you want;


data want;
update have(obs=0) have;
by ID;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User
You should show what you want as output but usually this works for what you want;


data want;
update have(obs=0) have;
by ID;
run;
JackHP
Fluorite | Level 6

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 2 replies
  • 2397 views
  • 1 like
  • 2 in conversation