BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

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;

 

techsassy
Obsidian | Level 7
Wow, it doesn't say Super User under your name for nothing, Tom! This is closer to what I was looking for, since it can be easily integrated with existing code that we have, but I'll have to digest on that new syntax for a bit. Thanks much!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 16 replies
  • 17031 views
  • 1 like
  • 5 in conversation