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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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