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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 15326 views
  • 1 like
  • 5 in conversation