BookmarkSubscribeRSS Feed
Paari
Calcite | Level 5

for example:

data abc;

input date format;

datalines;

24/12/1990

24dec1990

12/24/1990

;

run;

please answer

4 REPLIES 4
Amir
PROC Star

Hi,

Have you tried using the anydtdte format:

SAS(R) 9.3 Formats and Informats: Reference

For example:

input date anydtdte10.;

Regards,

Amir.

Vince28_Statcan
Quartz | Level 8

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

ballardw
Super User

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.

Vince28_Statcan
Quartz | Level 8


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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 605 views
  • 3 likes
  • 4 in conversation