Solved
New Contributor
Posts: 2

# How to convert Month values e.g. Jan, Feb, Mar ...Dec to a numeric variable i.e. 1,2,3...12

Hi there,

I'm new to SAS and am using SAS Enterprise Miner 14.1.

My problem is pretty simple (but so am I).

I have a variable "month" that can take the values Jan, Feb, Mar ... Dec but I want to create a new numeric variable from that, let's call it nmonth, that is = 1 if month=Jan, =2 if month = Feb etc.

The Help suggests Expression Builder seems to be the way to go but how do I get to this (if indeed this is the best way to go)?

Regards

Confused

Accepted Solutions
Solution
‎08-29-2015 01:47 PM
Valued Guide
Posts: 765

## Re: How to convert Month values e.g. Jan, Feb, Mar ...Dec to a numeric variable i.e. 1,2,3...12

Hi, here's a data step attempt (still an Enterprise Guide holdout).  The variable NEW is NUMERIC ...

data x;

input old :\$3. @@;

datalines;

JAN MAR OCT DEC

;

data x;

set x;

new = input(put(input(catt(old,'1960'),monyy.),month.),2.);

run;

DATA SET x

Obs    old    new

1     JAN     1

2     MAR     3

3     OCT    10

4     DEC    12

All Replies
Solution
‎08-29-2015 01:47 PM
Valued Guide
Posts: 765

## Re: How to convert Month values e.g. Jan, Feb, Mar ...Dec to a numeric variable i.e. 1,2,3...12

Hi, here's a data step attempt (still an Enterprise Guide holdout).  The variable NEW is NUMERIC ...

data x;

input old :\$3. @@;

datalines;

JAN MAR OCT DEC

;

data x;

set x;

new = input(put(input(catt(old,'1960'),monyy.),month.),2.);

run;

DATA SET x

Obs    old    new

1     JAN     1

2     MAR     3

3     OCT    10

4     DEC    12

New Contributor
Posts: 2

## Re: How to convert Month values e.g. Jan, Feb, Mar ...Dec to a numeric variable i.e. 1,2,3...12

Thanks MikeZdeb

🔒 This topic is solved and locked.