BookmarkSubscribeRSS Feed
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7
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
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
ChrisNZ
Tourmaline | Level 20
Pls see "How does one-to-many merge behave? " thread.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1015 views
  • 0 likes
  • 3 in conversation