BookmarkSubscribeRSS Feed
SMorrison07
Calcite | Level 5

Does anyone know how I can convert a character date format such as OCT to read as a new numeric data varialbe such as 10.

Thank you

4 REPLIES 4
Haikuo
Onyx | Level 15

data test;

input mon $;

NUM_MONTH=MONTH(INPUT(CATS('01',MON,'1960'),DATE9.));

PUT MON= NUM_MONTH=;

cards;

OCT

MAR

FEB

JAN

DEC

MAY

;

SMorrison07
Calcite | Level 5

thanks for the help. Much appreciated

Jagadishkatam
Amethyst | Level 16

i believe there is no informat to convert only the month to numeric, there are functions which can pull the month from the date, but to read only month to numeric i am not sure.

alternativly we can do the following, we can assign the informat by proc format to the month and asign the values, and then use the informat.

proc format fmtlib;

    invalue mon "JAN"=1

                "FEB"=2

                "MAR"=3

                "APR"=4

                "MAY"=5

                "JUN"=6

                "JUL"=7

                "AUG"=8

                "SEP"=9

                "OCT"=10

                "NOV"=11

                "DEC"=12;

run;

data have;

    input month$;

cards;

OCT

;

run;

data have_;

    set have;

    new=input(month,MON.);

run;

Appreciate if anyone can suggest me the informat or format which can convert only the month to numeric values

Thanks,

Jagadish

Thanks,
Jag
ballardw
Super User

You don't need two passes. Try

 

data have;

input month :Mon.;

cards;

OCT

;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1060 views
  • 4 likes
  • 4 in conversation