## creating a new variable

Solved
Occasional Contributor
Posts: 6

# creating a new variable

I am trying to generate a new variable for years of education using the EDUC99 variable. The data set came with these formats already embedded in it. How would I go about creating a new variable(s) for years of education using the educ99 variable?

value EDUC99_f
00 = "NIU"
01 = "No school completed"
09 = "12th grade, no diploma"
10 = "High school graduate, or GED"
11 = "Some college, no degree"
12 = "Associate degree, type of program not specified"
13 = "Associate degree, occupational program"
14 = "Associate degree, academic program"
15 = "Bachelors degree"
16 = "Masters degree"
17 = "Professional degree"
18 = "Doctorate degree"

Accepted Solutions
Solution
‎04-19-2016 11:56 AM
Super User
Posts: 13,583

## Re: creating a new variable

For some of these the value for years would be moderately easy:

Values of 6, 7, 8 and 9 are pretty explicit.

No school looks like 0 years to me. Haven't a clue what NIU might be though from it's possition I might consider missing for years.

For others you make an assumption, 10 (High School or GED equiv) seem like 12 would be reasonable.

Associate academic degrees are typically considered "2 year" degrees, so High School + 2 = 14.

Bachelor's Degree are "4 year" so high school +4 = 16,

Master's are "2 year" so Bachelor + 2 = 18.

Other's you could use either a minimum, maximum or average value. The choice might well depend on the types of research questions that might be involved.

The basic approach is still IF-Then-Else or Select when.

If EDUC99 = 01 then Years = 0;

Else if EDUC99 = 02 then Years = 4; /*use the maximum possible*/

else if EDUC99 = 03 then Years = 8;

The SELECT construct is good for this type of list.

``````data want;
set have;
select (EDUC99);
When(00) Year = .;
When(01) Year = 0;
When(04) Year = 4;
When(05) Year = 8;
When(06) Year = 9;
When(07) Year = 10;
When(08) Year = 11;
When(09) Year = 12;
When(10) Year = 12;
When(11) Year = 13;
When(12) Year = 14;
When(13) Year = 14;
When(14) Year = 14;
When(15) Year = 16;
When(16) Year = 18;
When(17) Year = 19;
When(18) Year = 20;
otherwise;
end;
run;``````

Another option would be a custom informat but I'll leave that up to your research. See Proc Format Invalue.

You could have added this information to your previous question: select the gear icon and "edit post" to add this.

All Replies
Solution
‎04-19-2016 11:56 AM
Super User
Posts: 13,583

## Re: creating a new variable

For some of these the value for years would be moderately easy:

Values of 6, 7, 8 and 9 are pretty explicit.

No school looks like 0 years to me. Haven't a clue what NIU might be though from it's possition I might consider missing for years.

For others you make an assumption, 10 (High School or GED equiv) seem like 12 would be reasonable.

Associate academic degrees are typically considered "2 year" degrees, so High School + 2 = 14.

Bachelor's Degree are "4 year" so high school +4 = 16,

Master's are "2 year" so Bachelor + 2 = 18.

Other's you could use either a minimum, maximum or average value. The choice might well depend on the types of research questions that might be involved.

The basic approach is still IF-Then-Else or Select when.

If EDUC99 = 01 then Years = 0;

Else if EDUC99 = 02 then Years = 4; /*use the maximum possible*/

else if EDUC99 = 03 then Years = 8;

The SELECT construct is good for this type of list.

``````data want;
set have;
select (EDUC99);
When(00) Year = .;
When(01) Year = 0;
When(04) Year = 4;
When(05) Year = 8;
When(06) Year = 9;
When(07) Year = 10;
When(08) Year = 11;
When(09) Year = 12;
When(10) Year = 12;
When(11) Year = 13;
When(12) Year = 14;
When(13) Year = 14;
When(14) Year = 14;
When(15) Year = 16;
When(16) Year = 18;
When(17) Year = 19;
When(18) Year = 20;
otherwise;
end;
run;``````

Another option would be a custom informat but I'll leave that up to your research. See Proc Format Invalue.

You could have added this information to your previous question: select the gear icon and "edit post" to add this.

Super User
Posts: 6,785

## Re: creating a new variable

The first thing you would do is inspect the data.  Does the variable EDUC99 always take on values that appear on this scale, or are there other values possible?

Assuming that the value always appears on this scale, the next thing you would do is decide how many years of education you would like to assign for each of the categories.  There are no guidelines available from a program ... it's  your decision.

Once those decisions are in place, you could write a set of IF/THEN statements within a DATA step.  For example:

data want;

set have;

if EDUC99=1 then years_of_education=0;

else if EDUC99=8 then years_of_education=11;

else if EDUC99=9 then years_of_education=12;

else ...

run;

I'm assuming that EDUC99 is numeric, because it is connected to a numeric format (EDUC99_f).  But if it turns out to be character, slight changes might be needed.

🔒 This topic is solved and locked.