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!
You didn't use an update statement your code has a set statement.
See this link on how to update a dataset:
You didn't use an update statement your code has a set statement.
See this link on how to update a dataset:
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
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.
Thank you Everyone!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.