Query regarding merging two datasets

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Query regarding merging two datasets

I have two datasets bsas1 and bsas2. I want to merge these datasets by name, therefore i used the command 'by name' but it didn't worked although when i run command 'by id' it worked. Why is it so ?. 

 

Below is the attached jpg screenshot.

Attachment

Accepted Solutions
Solution
‎05-07-2017 06:08 AM
Esteemed Advisor
Posts: 6,646

Re: Query regarding merging two datasets

A datastep merge with a by statement expects that the datasets are sorted in the order specified by the by statement. Use proc sort to achieve that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Valued Guide
Posts: 507

Re: Query regarding merging two datasets

Because your data is not sorted by name, but by ID. Run the code

 

proc sort data = bsas1;
	by name;
run;

proc sort data = bsas2;
	by name;
run;

and try again.

 

Solution
‎05-07-2017 06:08 AM
Esteemed Advisor
Posts: 6,646

Re: Query regarding merging two datasets

A datastep merge with a by statement expects that the datasets are sorted in the order specified by the by statement. Use proc sort to achieve that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 104 views
  • 3 likes
  • 3 in conversation