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.
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?
@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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.