Here is a method that doesn't require creating an INDEX. Instead it keeps a counter of the number of records read from the transaction file and then uses POINT= option on SET statement to re-read the observation many times. Note that if your transaction file introduces some NEW variables then you will need to remember to clear them out or else the last read value will be retained.Actually that was side effect of earlier version I tried where I had a KEEP= option on the MERGE statement.
data old_targets;
input keyvar $ oldvar $ commonvar;
datalines;
ACCT Sally 1
ACCT Steve 2
MGMT Tommy 1
MGMT Terri 1
UNKN New 2
;
data new_targets ;
input keyvar $ commonvar newvar $;
datalines;
ACCT 3 x
MGMT 3 y
UNUSED 4 z
;
data example4 ;
title1 'Example4 - Uses POINT= option';
merge old_targets(in=in_old) new_targets (in=in_new) ;
by keyvar ;
point + first.keyvar*in_new ;
if in_old;
if in_new then set new_targets point=point;
run;
proc print;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.