DATA Step, Macro, Functions and more

UPDATE

Accepted Solution Solved
Reply
Regular Contributor
Posts: 194
Accepted Solution

UPDATE

I've a field in a dataset, table a, I want to update; it has 9000  observations.

Table b has the new information; it has 9000 observations.

I used the update statement but am getting a table with 18,0000 observations.

Table A

scode field2     field3      field4

2               23     34543     233409

3               24     34569     800380

5              45                     098873                    

8              33                     093872

Table B

scode     field3

5              39849 

8              30987

DESIRED   OUTPUT Table

scode field2 field3      field4

2               23     34543     233409

3               24     34569     800380

5              45       39849     098873                    

8              33       30987       093872

 

What am I doing wrong?

Here's my code:

data updated;

     set sorted distorig;

     by scode;

run;

Any help you can give is much appreciated!


Accepted Solutions
Solution
‎03-15-2013 10:36 PM
Super User
Posts: 19,770

Re: UPDATE

You didn't use an update statement your code has a set statement.

See this link on how to update a dataset:

Step-by-Step Programming with Base SAS(R) Software

View solution in original post


All Replies
Solution
‎03-15-2013 10:36 PM
Super User
Posts: 19,770

Re: UPDATE

You didn't use an update statement your code has a set statement.

See this link on how to update a dataset:

Step-by-Step Programming with Base SAS(R) Software

Super Contributor
Posts: 644

Re: UPDATE

Cut to the chase

     data updated;

          update sorted distorig;

          by scode;

     run;

You can also update the original data in place

data sorted;

     update sorted distorig;

     by scode;

run;

but there is a risk that if for any reason the update fails you have a partially overwritten data set (SAS does not have rollback) so the first version is conservative.

Richard

Super User
Super User
Posts: 7,039

Re: UPDATE

You probably want to MERGE the datasets.  If you use MERGE then the values from the last dataset "win", even if the value is missing.  The UPDATE statement is really for when you have a dataset with transactions (changes) for specific variables. If you use the UPDATE statement then missing values will not overwrite (update) existing values in the "master" dataset.

Regular Contributor
Posts: 194

Re: UPDATE

Thank you Everyone!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 288 views
  • 6 likes
  • 4 in conversation