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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: