DATA Step, Macro, Functions and more

Merging data

Reply
Contributor
Posts: 32

Merging data

When I want to merge 6 datasets to one dataset like this:

*Merge datasets*;
DATA m.combined;
MERGE 	m.dataset1
	m.dataset2
	m.dataset3
	m.dataset4 
	m.dataset5
	m.dataset6; 
BY personnumber;
RUN;

Why do I get in my output table 3 times the same measurements for my personnumber like this:

 Personnumber

 Gender

Heigth

Weight

 1

 167

 56

 1

 167

 56

 1

 167

 56

 1

 188

 78

 1

 188

 78

 1

 188

 78

 2

 190

 102

 2

 190

 102

 2

 190

 102

 

I want to merge it like this:

 Personnumber

 Gender

 Heigth

Weight

 167

 56

 188

 78

 190

 102

 

There are no errors, so can someone please help? Thanks!

Super User
Posts: 9,548

Re: Merging data

It's in the data. Please post your datasets (in data steps).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 32

Re: Merging data

Posted in reply to KurtBremser

What do you mean? I can't post my whole dataset here..

Super User
Posts: 9,548

Re: Merging data

Just post the data (in all datasets) for persons 1, 2 and 3 (as mentioned in your original question).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 6,524

Re: Merging data

One of your incoming data sets (OK, possibly more than one) already contains multiple observations for each PERSONNUMBER.  You have to fix that data set first (again, possibly more than one data set to fix) if you want to end up with one observation apiece.

 

If you think it's legitimate that one of your incoming data sets contains multiple observations per personnumber, then you need to decide what should happen with those ... how can your input contain many, but your output only one?  What is the process to go through to narrow down the observations?

Ask a Question
Discussion stats
  • 4 replies
  • 135 views
  • 2 likes
  • 3 in conversation