Hi you can achieve this in SAS by merging the datasets based on the common variable VAR1 and then reassigning the record_ID to match the ID in SET1 . Here's how you can do it:
/* Step 1: Create SET1 */
data SET1;
input ID Var1 P1 $ P2 P3 P4 P5;
datalines;
1 3456
2 8796
3 2222
4 7689
;
run;
/* Step 2: Create SET2 */
data SET2;
input record_ID VAR1 B1 B2 B3 $ B4 B5;
datalines;
10 3456
12 8796
15 2222
20 7689
;
run;
/* Step 3: Merge datasets based on VAR1 */
proc sql;
create table merged as
select a.ID, a.Var1, a.P1, a.P2, a.P3, a.P4, a.P5,
b.B1, b.B2, b.B3, b.B4, b.B5
from SET1 as a
inner join SET2 as b
on a.Var1 = b.Var1;
quit;
/* Step 4: Display the merged dataset */
proc print data=merged;
run;
Using PROC SQL to merge datasets in SAS has several advantages:
Flexibility: PROC SQL allows for complex joins and merges, including inner joins, outer joins, and conditional joins, which can be more flexible than traditional DATA step merges.
Simplicity: The syntax for merging datasets using PROC SQL can be simpler and more intuitive, especially for those familiar with SQL.
References
Match Merging Data Files Using PROC SQL
... View more