Help using Base SAS procedures

How to format an existing variable

Frequent Contributor
Posts: 131

How to format an existing variable

I have a data set which has a few variables. One variable is called sex, which has a fixed length of 1, and formatted as $1. (i.e. M, or Female). This variable also has missing values. Now the question is to set the missing values as 'Other'. The following is what I did:

DATA work.test;
SET user.birth;
LENGTH sex $5.;
FORMAT sex $5.;
IF age=' ' THEN age='Other';

Unfortunately, the missing values are set to be 'O'. How can I correct this without using any new variable names?
Trusted Advisor
Posts: 2,114

Re: How to format an existing variable

Putting the LENGTH statement before the SET statement should do it.
Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation