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

Hello,

I am importing a csv file from excel and the dates that is pulled from the file contains time as well.  SAS is reading the dates correctly, however I want to change the DATETIME16. to MMYYDD10.  Any guidance on how to do this would be greatly appreciated.  

Thank you,
Jeff S. O.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you use a datastep program to read CSV (highly recommended) instead of proc import then you specify the informat and format in the datastep.

 

If you are going to be repeatedly importing similar format files you are almost gauranteed to get some inconsistency over time from changing lengths of character variables, change from numeric to character, from date to character or similar. Getting one datastep and modifying input file and output dataset will save you lots of headaches down the road.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Do

newdate = datepart(date);
format newdate mmddyy10.;

(there is no mmyydd format)

If you want to preserve the original variable name, add

drop date;
rename newdate=date;

in the data step.

ballardw
Super User

If you use a datastep program to read CSV (highly recommended) instead of proc import then you specify the informat and format in the datastep.

 

If you are going to be repeatedly importing similar format files you are almost gauranteed to get some inconsistency over time from changing lengths of character variables, change from numeric to character, from date to character or similar. Getting one datastep and modifying input file and output dataset will save you lots of headaches down the road.

Jolly
Calcite | Level 5

Hello Ballardw,

Would you mind giving a brief example?  I have always used the import statement, but if I can decide the format before the dataset is created, that sounds way better than what I have been doing. 

 

Thank you,
Jeff S O

ballardw
Super User

If you have been using Proc Import you should get code SAS generates to read a csv file in the log.

You can copy that and paste into the editor to see a basic example. Look at statements like INFORMAT. Those tell SAS how to read specific variables. When they are character the $nn sets the length of the text variables to nn characters.

 

Jolly
Calcite | Level 5

Thank you very much for that Ballardw!

Jeff S O

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1911 views
  • 0 likes
  • 3 in conversation