BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kayomole
Calcite | Level 5

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 .

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.);

 

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Tom
Super User Tom
Super User

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.);

 

Kayomole
Calcite | Level 5
Thank you. Dateform=INPUT(date,MMDDYY10.); works.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to connect to databases in SAS Viya

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.

Discussion stats
  • 3 replies
  • 1294 views
  • 1 like
  • 3 in conversation