how to read all dates formats values from rawfile ?

Reply
Occasional Contributor
Posts: 16

how to read all dates formats values from rawfile ?

for example:

data abc;

input date format;

datalines;

24/12/1990

24dec1990

12/24/1990

;

run;

please answer

Super Contributor
Posts: 282

Re: how to read all dates formats values from rawfile ?

Hi,

Have you tried using the anydtdte format:

SAS(R) 9.3 Formats and Informats: Reference

For example:

input date anydtdte10.;

Regards,

Amir.

Super Contributor
Posts: 339

Re: how to read all dates formats values from rawfile ?

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

Super User
Posts: 10,538

Re: how to read all dates formats values from rawfile ?

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.

Super Contributor
Posts: 339

Re: how to read all dates formats values from rawfile ?


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.

Ask a Question
Discussion stats
  • 4 replies
  • 217 views
  • 3 likes
  • 4 in conversation