DATA Step, Macro, Functions and more

Data Step Update Statement

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

Data Step Update Statement

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


Accepted Solutions
Solution
‎08-05-2016 01:42 PM
Super User
Posts: 10,035

Re: Data Step Update Statement

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


All Replies
Super User
Posts: 5,513

Re: Data Step 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.

Contributor
Posts: 30

Re: Data Step Update Statement

Posted in reply to Astounding

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

Super User
Posts: 5,513

Re: Data Step Update Statement

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.

Super User
Posts: 11,343

Re: Data Step Update Statement


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.

 

Super User
Posts: 11,343

Re: Data Step Update Statement

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;

Solution
‎08-05-2016 01:42 PM
Super User
Posts: 10,035

Re: Data Step Update Statement

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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 472 views
  • 0 likes
  • 4 in conversation