Which Function to Use to Update Database?

Reply
Regular Contributor
Posts: 152

Which Function to Use to Update Database?

Hello

I have a data set of patient data with an original and unique ID number per visit.  Occasionally the data is corrected so correction files are produced.   THese corrections could include visits not previously submitted and the corrections may only be for one data element.  What I would like to have happen is that any new abstracts will be added to the original data set from corrections and any data elements from corrections be updated in submissions.

The original file is "sub" and the corrected file is "corr".  Sub has 1506 records and corr has 13 but when I used update the subsequent dataset was 1065 so it didn't work as planned.  The code I used was:

data import_results;

update work.sub work.corr;

by Unique_Key;

run;

What function should I be using to get this to work as I'd like?  Thanks very much.

Esteemed Advisor
Posts: 7,300

Which Function to Use to Update Database?

Were both of your files sorted by Unique_Key ?  It they were, seeing your log would be needed to see what may have happened.

If they weren't, sort them, then retry your code and let us know if your problem was solved.

Super User
Super User
Posts: 6,380

Re: Which Function to Use to Update Database?

You need to include the visit variable in the BY statement.

UPDATE statement will collapse to one observation per BY group.

Regular Contributor
Posts: 152

Which Function to Use to Update Database?

Hi

I don't know what went wrong with the original but when I sorted them both by Unique_Key and then ran the update, I got 1506 records like I expected.  Thank you both for your replies!

Ask a Question
Discussion stats
  • 3 replies
  • 391 views
  • 0 likes
  • 3 in conversation