Hello,
I have character date 01/29/2019 (format $10, informat $10). I want to convert it into 2019-01-29. I searched online and tried different ways, but still not successful.
please help.
thanks!
@superbug wrote:
Hello,
I have character date 01/29/2019 (format $10, informat $10). I want to convert it into 2019-01-29. I searched online and tried different ways, but still not successful.
please help.
thanks!
Do you want to create an actual date variable?
date_var=input(char_var,mmddyy10.);
format date_var yymmdd10.;
Or another character variable?
char_var2=put(input(char_var,mmddyy10.),yymmdd10.);
@superbug wrote:
Hello,
I have character date 01/29/2019 (format $10, informat $10). I want to convert it into 2019-01-29. I searched online and tried different ways, but still not successful.
please help.
thanks!
Do you want to create an actual date variable?
date_var=input(char_var,mmddyy10.);
format date_var yymmdd10.;
Or another character variable?
char_var2=put(input(char_var,mmddyy10.),yymmdd10.);
Hi:
You need to create a new numeric variable using the INPUT function, as shown below:
In the above program, the variable CDATE is the character date from the input data. The variable BIRTHDAY is the numeric value that is the result of using the INPUT function on CDATE with the mmddyy10. informat. The INPUT function returns the value of the date as the number of days since Jan 1, 1960, which is how SAS date values are stored. The variables BDAY1 and BDAY2 are just copies of the BIRTHDAY variable so a different format can be applied.
In the PROC PRINT, there's no format applied to BIRTHDAY, so you can see how the value for the date is stored internally. Then, BDAY1 is formatted with the yymmdd10. format and BDAY2 is formatted with the worddate. format. The benefit of storing a date value as an offset from Jan 1 1960 is that the same number can use different formats to display the date however you wish.
Hope this helps,
cynthia
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.