I am using proc update to update one dataset from another. The number of observations are different in each dataset. Is there an efficient way to determine which observations have been updated? Ideally, I would like to create a flag variable so I can create a new dataset of non-updated data. I am updating by key, date, and type. Any help would be appreciated. Thank you
Here is a tweak to your program to push it in the right direction:
data update1(drop= var75 -- var77);
retain varlist;
update raw(in=a) ss(in=inb);
by key date type;
updated_flag = inb;
if a and last.type then output;
run;
I can't tell why you would need the RETAIN statement, but that part is up to you.
The coding change protects against having multiple updates for the same RAW observation, and outputting each change rather than all the changes after they have been applied.
The UPDATED_FLAG variable gets replaced each time. If you want to process multiple batches of updates, it is easy, but mildly more complex to track which observations have been updated by any of the batches of updates.
What documentation were you reading where you saw PROC UPDATE? I'm not sure such a thing exists in SAS.
Apologies not proc update, but a data step using the update statement.
Please show the code that you have attempted. There are a number of ways to "update" data sets, none are named Proc Update that I am aware of, and each has strengths and limitations.
Some details may be important: Does the "master" set that is to be updated have multiple values for the "key" or what ever you want to think of as the variables used to match records between the two?
Does the Transaction dataset have multiple values for the same matching variables? If multiples in the transaction do you need to know that more than one observation was used to update the master?
If a data step Update or even Merge was used this is next to trivial with the dataset in=option
data newset; update master transaction (in=intransaction) ; by matchingvariable; updatedflag=intransaction; run;
would set the variable updatedflag to 1 if the current observation has an observation from the transaction data set, 0 otherwise.
data update1(drop= var75 -- var77);
retain varlist;
update raw(in=a) ss(in=inb);
by key date type;
if a then output;
run;
This is the code I have run to update my data.
Here is a tweak to your program to push it in the right direction:
data update1(drop= var75 -- var77);
retain varlist;
update raw(in=a) ss(in=inb);
by key date type;
updated_flag = inb;
if a and last.type then output;
run;
I can't tell why you would need the RETAIN statement, but that part is up to you.
The coding change protects against having multiple updates for the same RAW observation, and outputting each change rather than all the changes after they have been applied.
The UPDATED_FLAG variable gets replaced each time. If you want to process multiple batches of updates, it is easy, but mildly more complex to track which observations have been updated by any of the batches of updates.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.