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;
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.
Asked, and answered, here:
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.