BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chinna0369
Pyrite | Level 9

Hi all, 

 

I am trying to convert character month to numeric. Can you please help me with this....

 

Thanks in advance! 

 

below is the data:

data month;
input m $5.;
datalines;
SEP
SEP
NOV
JAN
FEB
FEB
MAY
JAN
JUN
OCT
MAR
AUG
JUL
JUL
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way:

data month;
input m $5.;
monthnum = month(input(m||'2020',monyy7.));
datalines;
SEP
SEP
NOV
JAN
FEB
FEB
MAY
JAN
JUN
OCT
MAR
AUG
JUL
JUL
;
run;

which inputs a string with a year appended using a monyy informat and extracts the month from that.

Others 1) a bunch of If/then/else statements

2) a select/ when block (a bit better than if/then/else

3) a custom informat and and an input statement.

View solution in original post

2 REPLIES 2
Norman21
Lapis Lazuli | Level 10

Asked, and answered, here:

 

https://communities.sas.com/t5/SAS-Enterprise-Guide/converting-month-to-number-from-1-to-12/td-p/492...

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

ballardw
Super User

One way:

data month;
input m $5.;
monthnum = month(input(m||'2020',monyy7.));
datalines;
SEP
SEP
NOV
JAN
FEB
FEB
MAY
JAN
JUN
OCT
MAR
AUG
JUL
JUL
;
run;

which inputs a string with a year appended using a monyy informat and extracts the month from that.

Others 1) a bunch of If/then/else statements

2) a select/ when block (a bit better than if/then/else

3) a custom informat and and an input statement.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 6086 views
  • 1 like
  • 3 in conversation