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

I have 2 vars (char type):

 

date 1           date 2

26/07/2013   10/04/2014 07:50:11 p.m.
28/02/2013   12/09/2012 12:46:29

 

I need to convert to data type, how can I do it?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Your problem description talks about dates, and not datetimes.  To get dates only, you could use:

 

date_1_converted = input(date1, ddmmyy10.);

date_2_converted = input(date2, ddmmyy10.);

format date_1_converted date_2_converted yymmdd10.;

 

There's no need to apply YYMMDD10 as the final format.  That's just an example of what is possible.

 

Also note, it's not 100% clear that DATE_2_CONVERTED should apply the DDMMYY10 informat to convert it.  That would be applicable when the character values actually include the day then the month then the year.  But it's also conceivable that the character values contain the month then the day then the year.  In that case, convert with:

 

date_2_converted = input(date2, mmddyy10.);

View solution in original post

2 REPLIES 2
Reeza
Super User

Use the INPUT function. 

 

 

NEW_VAR = INPUT( old_var_name, current_format);

 

Astounding
PROC Star

Your problem description talks about dates, and not datetimes.  To get dates only, you could use:

 

date_1_converted = input(date1, ddmmyy10.);

date_2_converted = input(date2, ddmmyy10.);

format date_1_converted date_2_converted yymmdd10.;

 

There's no need to apply YYMMDD10 as the final format.  That's just an example of what is possible.

 

Also note, it's not 100% clear that DATE_2_CONVERTED should apply the DDMMYY10 informat to convert it.  That would be applicable when the character values actually include the day then the month then the year.  But it's also conceivable that the character values contain the month then the day then the year.  In that case, convert with:

 

date_2_converted = input(date2, mmddyy10.);

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 672 views
  • 2 likes
  • 3 in conversation