mata sabine fonderson
mata sabine fonderson

Reputation: 21

Replacing empty cells in a variable with values from another

I have a dataset with a number of columns. Two of them are practically the same however in variable column 1 there are string data that I would like to extract and replace in empty cells of variable column 2.

I tried using the syntax

If 
    variable_2 = "".
    Compute variable_1 = variable_2.
End If

But do not get anything. Please, could someone help with this?

Much appreciated.

Upvotes: 2

Views: 1416

Answers (1)

eli-k
eli-k

Reputation: 11360

This should be either

if var2="" var2=var1.

(no period after the condition, no "end if")

OR

do if var2="". 
compute var2=var1. 
end if.

(this is a "do if" and not just an "if" - enables you to add commands after the condition, and not needed here).

In any case, if variable_2 is empty you want to run variable_2=variable_1 and not the reverse.

Upvotes: 1

Related Questions