Help using Base SAS procedures

Merging by Primary Keys

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Merging by Primary Keys

Hi,

I am merging two datasets but I am getting both primary and secondary match. I just want secondary variables for primary dataset. How do I do that. This my program so far..

PROC SORT DATA = ABCD;

BY VAR1;

RUN;

PROC SORT DATA = XYZ;

BY VAR1;

RUN;

DATA PQRS;

MERGE ABCD XYZ;

BY VAR1;

RUN;


Accepted Solutions
Solution
‎09-29-2011 12:19 PM
PROC Star
Posts: 7,468

Merging by Primary Keys

Posted in reply to akberali67

I'm not sure what you are asking unless it is that you only want records from xyz if they are also in abcd.  If so, then just change your last datastep to:

DATA PQRS;

  MERGE ABCD (in=ina) XYZ;

  BY VAR1;

  if ina;

RUN;

View solution in original post


All Replies
Solution
‎09-29-2011 12:19 PM
PROC Star
Posts: 7,468

Merging by Primary Keys

Posted in reply to akberali67

I'm not sure what you are asking unless it is that you only want records from xyz if they are also in abcd.  If so, then just change your last datastep to:

DATA PQRS;

  MERGE ABCD (in=ina) XYZ;

  BY VAR1;

  if ina;

RUN;

Contributor
Posts: 37

Merging by Primary Keys

That was it, I shud have thought of that, thanks for the help,,Smiley Happy

🔒 This topic is solved and locked.

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

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