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.);
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.