Hi all,
I want to change the date format of my data to YYMMDD8. . The data has two different date formats. They are:
1. DD/MM/YY (DDMMYYw.)
2. DD/MM/YYYY (DDMMYY10.)
Usually, I use the code below to change the date to the needed format.
Dateform = INPUT(PUT(date,8.),YYMMDD8.);
FORMAT Dateform YYMMDD8.;
RUN;
However, when I run the code now, it reads the 'day' as 'year' for both date formats. Please how can I solve this problem? Thank you .
It is reading the DD as the YY because that is what you told it do by using the YYMMDD informat instead of the DDMMYY informat.
Is your data in a numeric variable? If so then why did you show the values as having slashes in them?
Is your data in a character variable? If so then just use the INPUT() function on it. You should use a width of 10 to handle both the records with and without the century part of the year.
Dateform = INPUT(date,DDMMYY10.);
Can you clarify, you have data which is in SAS numeric date format? If so then you just need to apply the format statement, you wouldn't input(put) it again.
It is reading the DD as the YY because that is what you told it do by using the YYMMDD informat instead of the DDMMYY informat.
Is your data in a numeric variable? If so then why did you show the values as having slashes in them?
Is your data in a character variable? If so then just use the INPUT() function on it. You should use a width of 10 to handle both the records with and without the century part of the year.
Dateform = INPUT(date,DDMMYY10.);
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.