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?
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.);
Use the INPUT function.
NEW_VAR = INPUT( old_var_name, current_format);
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.);
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.
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.