DATA Step, Macro, Functions and more

UPDATE one variable using another variable in the same dataset.

Accepted Solution Solved
Reply
Regular Contributor
Posts: 194
Accepted Solution

UPDATE one variable using another variable in the same dataset.

Hello. This Question has 2 steps:

I've a dataset, Table A with a variable, 'dist' which may have incorrect values. and have added a new variable 'dist_orig' which has the updated values.

However, 'dist_orig' only has updated values for some but not all observations (i.e, some are missing).  Therefore I don't want to overwrite 'dist' with missing values in 'dist_orig';

I want to retain values of 'dist' for which I"m missing values in 'dist_orig'.

The ulitmate goal is to update the variable 'dist' with the values in dist_org.

I know how to do it if I divide Table A into 2 datasets and use the UPDATE statement.

But, how do you update 'dist' with values in 'dist_orig' if they're in the same dataset?



Accepted Solutions
Solution
‎03-18-2013 04:09 PM
Respected Advisor
Posts: 3,156

Re: UPDATE one variable using another variable in the same dataset.

if both variables are numeric:

dist=coalesce(dist_org,dist);

or they are Char:

dist=coalescec(dist_org,dist);

Check docs for details.

Haikuo

Update:

deleted.

View solution in original post


All Replies
Solution
‎03-18-2013 04:09 PM
Respected Advisor
Posts: 3,156

Re: UPDATE one variable using another variable in the same dataset.

if both variables are numeric:

dist=coalesce(dist_org,dist);

or they are Char:

dist=coalescec(dist_org,dist);

Check docs for details.

Haikuo

Update:

deleted.

Regular Contributor
Posts: 194

Re: UPDATE one variable using another variable in the same dataset.

Thank you very much!!Smiley Happy

🔒 This topic is solved and locked.

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

Discussion stats
  • 2 replies
  • 187 views
  • 0 likes
  • 2 in conversation