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.
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.
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.
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.
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
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.
Thank you very much for that Ballardw!
Jeff S O
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.