BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
J_squared
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;

View solution in original post

8 REPLIES 8
ballardw
Super User

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;

ChrisHemedinger
Community Manager

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:

fmt.png

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
J_squared
Calcite | Level 5

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!

EURDFDD10.png

ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
J_squared
Calcite | Level 5

Like this...

datestyle_path.png

The datestyle program contains the following...

program.png

ChrisHemedinger
Community Manager

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
J_squared
Calcite | Level 5

LOL a pupil is only as good has his/her instructor! Smiley Happy

J_squared
Calcite | Level 5

Thank you very much!  That worked nicely!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 2015 views
  • 2 likes
  • 3 in conversation