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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2563 views
  • 1 like
  • 2 in conversation