Fluorite | Level 6

## month change in numaric

Hi I'm tried  to convert month (e.g. JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC) this one change's to numaric month 01,02,03....etc please tell me how to change in easy method .   i tried this one below.

if Month="JAN" then m="01";
if Month="FEB" then m="02";
if Month="MAR" then m="03";
if Month="APR" then m="04";
if Month="MAY" then m="05";
if Month="JUN" then m="06";
if Month="JUL" then m="07";
if Month="AUG" then m="08";
if Month="SEP" then m="09";
if Month="OCT" then m="10";
if Month="NOV" then m="11";
if Month="DEC" then m="12";

1 ACCEPTED SOLUTION

Accepted Solutions
Barite | Level 11

## Re: month change in numaric

If you want m to be a char variable instead, apply the put function to the result like below:

``````data want;
set have;
m=put(month(input(cats('01',month,'2010'),date9.)),z2.);
run;``````

Danile Santos @ www.cgd.pt

5 REPLIES 5
Diamond | Level 26

## Re: month change in numaric

Follow the guidance you will see at the bottom of where you post.  Post example test data in the form of a datastep.  This is critical for us to see as we don't know what you are working with.  For example, if you data is a numeric SAS date, you could simply use the month() function to extract month name.  This being know, if you have a character variable with month, then thinking logically you could append 01 and 2010 to that month, create a date variable and then extract using the month() function.  As I have no test data I am going to assume month variable is character:

```data want;
set have;
m=month(input(cats('01',month,'2010'),date9.));
run;```

You could also create a format for it - though I personal avoid compiled anything as much as possible so would go with the above.

Fluorite | Level 6

## Re: month change in numaric

Am working with clinical data, char_variable have months name as "JAN"
etc.. i want to convert it to numeric version of months to other variable,
please let me know how it can be done in data step

Thanks again!
Teja

attachments. -##
Diamond | Level 26

## Re: month change in numaric

You will want to try the datastep I posted which does exactly what you ask for.

As a note, you are getting data from a database in date parts yes.  If so then I recommend you get to one of the CDISC models, i.e. have a character date field which is the various parts of the date in ISO format, and also if you doing an analysis model then have a numeric date variable as well - this gives you the best of both worlds.

Barite | Level 11

## Re: month change in numaric

If you want m to be a char variable instead, apply the put function to the result like below:

``````data want;
set have;
m=put(month(input(cats('01',month,'2010'),date9.)),z2.);
run;``````

Danile Santos @ www.cgd.pt

PROC Star

## Re: month change in numaric

If I understand correctly, M is coming out as numeric when you would like it to be character.  If that is the problem, your code is correct as is.  The problem is that your data set already contains M and it is already defined as numeric.  You can change this by getting rid of the old M:

data want;

set have (drop=M);

* All your IF/THEN statements here;

run;

Discussion stats
• 5 replies
• 1172 views
• 2 likes
• 4 in conversation