BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
SAS doesn't know whether ambiguous data is in mdy form or dmy form. Do you know? If so, you can use the DATESTYLE option to tell SAS which interpretation to use, either of:

options datestyle=dmy;

options datestyle=mdy;

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Please include text (like code and data) in your message directly, rather than through attachments. Many people will not download attachments, and specifically Microsoft Office documents are a security threat when downloaded.

--
Paige Miller
VictorHsieh
Calcite | Level 5
The issues are that y=input(put(dp1,10.),anydtdte10.); did not convert dp1(4/1/2021) into right date. Instead, y(1/4/2021) was converted. The question is that how does anydtdte know dp1 is mmddyy format or ddmmyy format. In the whole report that from 4/1/2021 through 14/12/2021 were treated as ddmmyy until reaching 4/13/2021, then were treated as mmddyy format.
Please advose. Thank you.
VictorHsieh
Calcite | Level 5
y=input(put(dp1,10.),anydtdte10.);
format y mmddyy10.;
wday1=weekday(y);
Obs incident idx1 idx2 dp1 dp y wday1 createdon_d CreatedOn resolvedon_d Resolvedon closedon_d Closedon
1 81402 STG CSV 4/1/2021 . 1/4/2021 2 4/1/2021 10:43 4/1/2021 5:43 NULL 4/1/2021 10:45 4/1/2021 5:45
2 81403 STG CSV 4/1/2021 . 1/4/2021 2 4/1/2021 10:43 4/1/2021 5:43 NULL 4/1/2021 10:46 4/1/2021 5:46

Why dp1 was converted from 4/1/2021 into 1/4/2021?
Tom
Super User Tom
Super User

The ANYDTxxxx informat will have to GUESS which parts of the string is the month and which is day when the day value is less than 13.   It will use the DATESTYLE setting to tell it which to use.

 

Set it to the style you want it to use. 

 

I cannot tell from your question whether you want MDY or DMY.

 

Is '4/1/2021' supposed to be the fourth of January or April first?

Sajid01
Meteorite | Level 14

@VictorHsieh 
The following option will tell you what the data style will be in the case of ambiguity.

proc options option=datestyle;
run;

If the response in the log output is like the following

 DATESTYLE=MDY     Specifies the sequence of month, day, and year when ANYDTDTE, ANYDTDTM, or ANYDTTME informat data is ambiguous.

You need to run this option on your system and it will explain.

 

s_lassen
Meteorite | Level 14

Why dp1 was converted from 4/1/2021 into 1/4/2021?

That depends, in the end, on the SAS installation you are running on. As @Astounding remarked, SAS does not "know" which date informat you want as the default. It guesses from the setting of the LOCALE system option, if it is European you will most often get DMY, if it is American, you will definitely get MDY. So, if you are using ANYDTDTE., always assign the DATESTYLE option first. Otherwise, your program will give one result on some installations, and another on other installations.

 

Being European (Danish) myself, I work half the time (or thereabout) on installations that use LOCALE=DA_DK, and the rest of the time on installations using the SAS System default, which is EN_US or something like that. And they give different results for ANYDTDTE without the DATESTYLE option.

Astounding
PROC Star
SAS doesn't know whether ambiguous data is in mdy form or dmy form. Do you know? If so, you can use the DATESTYLE option to tell SAS which interpretation to use, either of:

options datestyle=dmy;

options datestyle=mdy;
VictorHsieh
Calcite | Level 5
Thanks, Astounding.
You save me a lot of time by try and error.
The example of the answer are as follows:
data two;
infile CSV;
OPTIONS DATESTYLE=MDY;
INPUT
@1 Incident best12.
@14 Summary $1.
...

Victor

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 3634 views
  • 1 like
  • 6 in conversation