Is there a system variable that will tell me which rows were updated when utilizing the UPDATE statement?
It depends on what you mean by a row being updated.
data want;
update master trans (in=in_trans);
by id;
updated = in_trans;
run;
The variable UPDATED tells you whether a record was found in the transaction file for that ID. However, it doesn't tell you whether the data values actually changed the contents of the MASTER data set. It would still be possible that all data values in TRANS had missing values and were ignored, or that the values in TRANS matched what was already in MASTER.
What I'm seeking are two things 1) were any records appended (new records) and 2) were any variable values changed
In that case, there is no system tool. You would have to run a PROC COMPARE after the fact (with a BY statement), to find differences between the original and the new data set.
@Doug____ wrote:
What I'm seeking are two things 1) were any records appended (new records) and 2) were any variable values changed
Then something like this
data health2;
update health (in=a)
fitness(in=b);
by id name team;
Updated = b;
If a and b then Updated=1;
If not(a) and b then New=1;
run;
Though the example data I posted below didn't have any new records as that wasn't what your intial post implied.
No automatic variable that I am aware of but here is code that shows one way of adding your own as part of an update.
Note that the first bits are just to provide example data the last datastep has one technique.
Data HEALTH ;
input ID NAME $ TEAM $ WEIGHT ;
datalines;
1114 sally blue 125
1441 sue green 145
1750 joey red 189
1994 mark yellow 165
2304 joe red 170
;
run;
Data FITNESS ;
input ID NAME $ TEAM $ WEIGHT;
datalines;
1114 sally blue 119
1994 mark yellow 174
2304 joe red 170
;
run;
proc sort data=health;
by id name team;
run;
proc sort data=fitness;
by id name team;
run;
/* Update Master with Transaction */
data health2;
update health
fitness(in=b);
by id name team;
Updated = b;
run;
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!
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.