BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Doug____
Pyrite | Level 9

Is there a system variable that will tell me which rows were updated when utilizing the UPDATE statement?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
You need create Integrate Constraint on your table , and proc print it. 1) proc datasets ......... modify have; ic create sex=(sex is not missing.......) ...... audit have; initiate; quit; data have; update have temp; by id; run; proc print data=have(type=audit);run;

View solution in original post

6 REPLIES 6
Astounding
PROC Star

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.

Doug____
Pyrite | Level 9

What I'm seeking are two things 1) were any records appended (new records) and 2) were any variable values changed

Astounding
PROC Star

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.

ballardw
Super User

@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.

 

ballardw
Super User

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;

Ksharp
Super User
You need create Integrate Constraint on your table , and proc print it. 1) proc datasets ......... modify have; ic create sex=(sex is not missing.......) ...... audit have; initiate; quit; data have; update have temp; by id; run; proc print data=have(type=audit);run;

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
  • 6 replies
  • 2081 views
  • 0 likes
  • 4 in conversation