BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

I have a data set with dates in really really all types of "formats" like:

01/1/2001, 1/1/2001, 1/01/2001, 1/1/00, 01/1/00, 1/01/00. Is there a quick way to format all these exceptions in dd/mm/yyyy? 

Thank you very much. If I use for example: format date*, does it will take all the exceptions? The records are really many and so I cannot check for each single case. I must be sure that all the dates are in the same file format.

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The only way this question makes any sense is if the variable is a character string instead of a DATE.  (SAS stores dates as number of days since 1960).

 

If those strings are all supposed to represent day, month, and year values then you can use the DDMMYY informat to convert the string into a date value.  You could then leave it as a numeric value and apply any date type FORMAT to it you want. 

data want;
  set have;
   date = input(date_string,ddmmyy10.);
   format date yymmdd10.;
run;

Or you could use the PUT() function to use the format to generate a new character string.  

Then if you want you could overwrite the original character variable's vlaue.

data want;
  set have;
   date_string = put(input(date_string,ddmmyy10.),yymmdd10.);
run;

NOTE: I have used the YYMMDD format in my code so that the dates will be displayed in Year, Month, Day order.  If you display dates in DMY or MDY order you will confuse 50% of your audience.  If you really insist on seeing the dates in dd/mm/yyyy style then just use the DDMMYYS10. format instead.

 

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

The only way this question makes any sense is if the variable is a character string instead of a DATE.  (SAS stores dates as number of days since 1960).

 

If those strings are all supposed to represent day, month, and year values then you can use the DDMMYY informat to convert the string into a date value.  You could then leave it as a numeric value and apply any date type FORMAT to it you want. 

data want;
  set have;
   date = input(date_string,ddmmyy10.);
   format date yymmdd10.;
run;

Or you could use the PUT() function to use the format to generate a new character string.  

Then if you want you could overwrite the original character variable's vlaue.

data want;
  set have;
   date_string = put(input(date_string,ddmmyy10.),yymmdd10.);
run;

NOTE: I have used the YYMMDD format in my code so that the dates will be displayed in Year, Month, Day order.  If you display dates in DMY or MDY order you will confuse 50% of your audience.  If you really insist on seeing the dates in dd/mm/yyyy style then just use the DDMMYYS10. format instead.

 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 519 views
  • 1 like
  • 2 in conversation