for example:
data abc;
input date format;
datalines;
24/12/1990
24dec1990
12/24/1990
;
run;
please answer
Hi,
Have you tried using the anydtdte format:
SAS(R) 9.3 Formats and Informats: Reference
For example:
input date anydtdte10.;
Regards,
Amir.
Amir's proposed solution is pretty much your only hope. If somehow one of your date format isn't supported by the anydate format used, or (and you should spend some verification time on this) messes up years and days for some format, you are pretty much bound to importing them as character, creating a custom solution with a series of if covering all the different formats in your dataset to input them into a new numeric date variable with the proper format.
*edit* If you have 6-digit dates that are always of the same form mdy, dym, ydm etc., look for the DATESTYLE= system option with your anydtdte format.
Vincent
If you have data as in your example:
data abc;
input date format;
datalines;
24/12/1990
12/24/1990
;
How will you know the meaning of 07/03/1990 ? Any of the month/day 01 to 12 will be extemely problematical as to accuracy when the month/day and day/month is not entered with a fixed standard pattern.
If there is really a case where YMD/DMY etc. can be different, then anydtdte won't work and you are stuck with a custom solution. That is, reading them as a string, using a bunch of ifs with substring or prx and using input(var, properformat.). Sadly though if there is no additionnal variable to allow to distinguish 03/07/1990 from 07/03/1990, there really isn't anything that you can do nor that SAS can do.
Well, in theory, anydtdte can still read all dates. It will read unambiguous dates (like 24/12/1990 vs 12/24/1990) properly but will use whatever the DATESTYLE= system option is set to for all ambiguous cases.
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: