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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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

RichardinOz
Quartz | Level 8

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

Tom
Super User Tom
Super User

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.

jcis7
Pyrite | Level 9

Thank you Everyone!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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