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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.