Hello!
I have a .csv file that is an extract from SAP. The all dates have the following format: dd.mm.yyyy. I would like to properly convert this to DATE9. format using EG. Any suggestions?
-Joshua
Read the variable(s) using the ddmmyy format and assign the date9. format.
And you aren't "converting" but creating a SAS date valued variable. Then you can display and manipulate the variables with many formats or date functions.
data test;
informat date ddmmyy10.;
input date;
format date date9.;
datalines;
15.04.2012
;
run;
Read the variable(s) using the ddmmyy format and assign the date9. format.
And you aren't "converting" but creating a SAS date valued variable. Then you can display and manipulate the variables with many formats or date functions.
data test;
informat date ddmmyy10.;
input date;
format date date9.;
datalines;
15.04.2012
;
run;
And if you're using the Import Data task to accomplish this, you can Modify the input Source Informat on the Field Attributes screen. Select the column, click Modify, then specify the DDMMYY10. informat:
Thanks, Chris! I also used your suggestion regarding the ANYDTDTE informat... I changed the default field attribute for this variable from Type: String to Type: Date and then changed the Input format from DATE9. to ANYDTDTE10. as well... The output looks correct!
Great! Just keep in mind that the OPTIONS DATESTYLE= value will influence how the "ambiguous" dates turn out when using the ANYDT* collection of SAS informats.
options datestyle=mdy; /* 01.12.2015 will come in as 12JAN2015 */
options datestyle=dmy; /* 01.12.2015 will come in as 01DEC2015 */
You can add the proper option as a SAS program node ahead of the Import Data step to control this. You might also want to set it back to the default (DATESTYLE=LOCALE) when done.
Like this...
The datestyle program contains the following...
You got it! Such a fast learner.
Don't tell the others, but you were one of my best students in our class. I don't like to play favorites, but you were definitely in the top 6.
LOL a pupil is only as good has his/her instructor!
Thank you very much! That worked nicely!
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 25. 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.