TheNewGuy
TheNewGuy

Reputation: 579

Merging data sets with 2 different variables

This is my second day with SAS, I'm trying to merge VEKP and LIPS where VEKP has variable VPOBJKEY and LIPS has variable VBELN. VPOBJKEY and VBELN have the same data. I've searched the forum and found that I can rename them. Here is what I got so far but still cant get to the bottom. Any help would be appreciated. Thank you

DATA TYPE (KEEP= EXIDV VHILM VPOBJKEY);
SET HD.VEKP;
WHERE VHILM = "H3";
RUN;

DATA MATERIAL (RENAME=(VBELN=VPOBJKEY)KEEP= VBELN MATNR);
SET HD.LIPS;
RUN;

DATA COMBINED;
MERGE MATERIAL (IN=INA)
TYPE (IN=INB);
BY VBELN;
IF INA AND INB THEN OUTPUT COMBINED;
RUN;

Upvotes: 0

Views: 94

Answers (2)

TheNewGuy
TheNewGuy

Reputation: 579

Well I believe I figured it out.

DATA TYPE (KEEP= EXIDV VHILM VPOBJKEY);
SET HD.VEKP;
WHERE VHILM = "H3";
RUN;
PROC SORT DATA=TYPE; BY VPOBJKEY; RUN;

DATA MATERIAL (RENAME=(VBELN=VPOBJKEY)KEEP= VBELN MATNR);
SET HD.LIPS;
RUN;
PROC SORT DATA= MATERIAL; BY VPOBJKEY; RUN;
DATA COMBINED;
MERGE MATERIAL (IN=INA)
TYPE (IN=INB);
BY VPOBJKEY;
IF INA AND INB THEN OUTPUT COMBINED;
RUN;

Upvotes: 1

user667489
user667489

Reputation: 9569

After you've done the rename in the set statement, MATERIAL contains a variable called VPOBJKEY, not a variable called VBELN. Try merging by VPOBJKEY instead.

Upvotes: 0

Related Questions