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

Greetings Community,

 

I have this text variable that captures the dates

 

03/15/2015

3/17/2016

 

Some with leading zeros (for Jan to Sep), and some without the leading zeros. I need to convert it into a date format.

 

I tried this code:

Correct_date = input(text_date,ddmmyy10.) ;

format Correct_date YYMMDD10.;

 

I received this error:

NOTE: Invalid argument to function INPUT at line 30 column 15.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Sure thing 🙂

 

data have;
text_date="03/15/2015";output;
text_date="3/17/2016";output;
text_date="05/0/2015";output;
text_date="11/0/2016";output;
run;

data want;
   set have;
   text_date=tranwrd(text_date, '/0/', '/1/');
   Correct_date = input(text_date,mmddyy10.);
   format Correct_date mmddyy10.;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

You almost have it. You have to use the MMDDYY10. informat and not the DDMMYY10. Like this 

 

data have;
text_date="03/15/2015";output;
text_date="3/17/2016";output;
run;

data want;
   set have;
   Correct_date = input(text_date,mmddyy10.);
   format Correct_date mmddyy10.;
run;

 

altijani
Quartz | Level 8

Thank you for the code. I found where the problem is. I have some dates with month and year, but that have 0 for the day as follows:

 

05/0/2015

11/0/2016

 

The converted dates with your code are missings. I need to convert them to the beginning of the month, if the day is 0 as follows:

05/01/2015

11/01/2016

 

 

Any idea how that can be done?

 

Thanks! 

PeterClemmensen
Tourmaline | Level 20

Sure thing 🙂

 

data have;
text_date="03/15/2015";output;
text_date="3/17/2016";output;
text_date="05/0/2015";output;
text_date="11/0/2016";output;
run;

data want;
   set have;
   text_date=tranwrd(text_date, '/0/', '/1/');
   Correct_date = input(text_date,mmddyy10.);
   format Correct_date mmddyy10.;
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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1355 views
  • 1 like
  • 2 in conversation