Buras
Buras

Reputation: 3099

How to recode variables in SAS?

I tried to recode the missing values but instead lost all my other variables within a dataset


BEFORE:

enter image description here


AFTER:

        data work.newdataset;
        if (year =.) then year = 2000;
        run;

enter image description here

Upvotes: 1

Views: 2148

Answers (1)

Joe
Joe

Reputation: 63424

You are missing the SET statement.

data want;
set have;
myvar=5;
run;

will create a new dataset, want, from have, with the new variable value applied (or the recode or whatever). You could also do

data have;
set have;
myvar=5;
run;

That would replace have with itself plus the recode/whatever. This is actually less common in SAS; it is often preferable to do all recodes in one step, but to create a new dataset (so that the code is reversible easily).

Upvotes: 3

Related Questions