BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

What documentation were you reading where you saw PROC UPDATE?  I'm not sure such a thing exists in SAS.

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Apologies not proc update, but a data step using the update statement. 

ballardw
Super User

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.

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
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. 

Astounding
PROC Star

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.

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 937 views
  • 0 likes
  • 3 in conversation