DATA Step, Macro, Functions and more

how do I update value using merge statment

Reply
Frequent Contributor
Frequent Contributor
Posts: 81

how do I update value using merge statment

Hers is my coding
DATA TEMP1;
INPUT X 1. Y 1. Z $1.;
CARDS;
12A
23G
13D
;
RUN;

DATA TEMP2;
INPUT X 1. Z $1.;
CARDS;
1C
2B
;
RUN;

PROC SORT DATA=TEMP1;
BY X;
RUN;
PROC SORT DATA=TEMP2;
BY X;
RUN;

DATA TEMP;
MERGE TEMP1(IN=A) TEMP2(IN=B);
BY X;
IF A AND B;
RUN;

PROC PRINT DATA=TEMP;
RUN;
It output results as follow
x y z
1 2 C
1 3 D
2 3 B

but I expect the below output
x y z
1 2 C
1 3 C
2 3 B

It seems like my coding update only the 1st by value(1 2 A)not the second(1 3 D).

How do I update any duplicate value using merging statment.

Thanks so much in advance for your help.

Regards.

Inp
Super Contributor
Super Contributor
Posts: 3,174

Re: how do I update value using merge statment

The order of your datasets listed on the MERGE statement is critical with a match-merge process, where there are duplicate variable names in more than one file you are merging. The SAS-hosted documentation at the link below discusses, in detail, the topic of One-to-One Merging and provides a specific CAUTION on this topic and the behavior you observed.

Scott Barry
SBBWorks, Inc.


SAS 9.2 Language Reference: Concepts, Combining SAS Data Sets: Methods
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001081414.htm
PROC Star
Posts: 1,562

Re: how do I update value using merge statment

Pls see "How does one-to-many merge behave? " thread.
Ask a Question
Discussion stats
  • 2 replies
  • 126 views
  • 0 likes
  • 3 in conversation