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

Hi there,

 

I am trying to convert character formatted date which look like OCT2017_Default to date formatted OCT2017.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use the monyy informat/format:

data _null_;
date_str = "OCT2017_Default";
date_num = input(date_str,monyy7.);
format date_num monyy7.;
put date_num=;
run;

And use a more descriptive subject next time. "Base SAS" in the "Base SAS Programming" community is not showing off a lot of creativity, to be very polite.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Use the monyy informat/format:

data _null_;
date_str = "OCT2017_Default";
date_num = input(date_str,monyy7.);
format date_num monyy7.;
put date_num=;
run;

And use a more descriptive subject next time. "Base SAS" in the "Base SAS Programming" community is not showing off a lot of creativity, to be very polite.

PaigeMiller
Diamond | Level 26

I did not know that the MONYY7. format would exclude the part of the text string that is '_Default', I thought this would cause the conversion to fail.

 

Learn something new every day!

--
Paige Miller
Kurt_Bremser
Super User

This seems to be a feature of numeric informats, they only use the number of characters specified:

data _null_;
num_str = "1234567some_garbage";
num_num = input(num_str,7.);
put num_num=;
run;
PaigeMiller
Diamond | Level 26

So this fails, as I would have expected

 

num_num = input(num_str,8.);
--
Paige Miller

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!

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
  • 4 replies
  • 775 views
  • 2 likes
  • 3 in conversation