Hello! I'm trying to read in a date variable from a text file. The dates are formatted like this:
1/1/2000
1/15/2000
12/1/2000
12/12/2000
There are no leading zeroes on the month or day pieces of the date. I've tried using the ANYDTDTE informat, but it is only recognizing the dates with two digit days, and any date with a one digit day is showing up as missing. I've also tried a few other date informats, but I think since the lengths of the dates in the text file are not consistent, they are not working either. Here is my code:
Data Sample;
Infile 'File_1.txt' dlm='|' firstobs=2 truncover;
input ID $ date ANYDTDTE.;
format date mmddyy10.
run;
Any suggestions?
In your very code, you could use a modified list input using an informat than a formatted input and let : colon format modifier to perform the task of not reading any chars once a delimiter is reached/found.
I.e : ANYDTDTE /*notice the colon*/
Data Sample;
Infile 'File_1.txt' dlm='|' firstobs=2 truncover;
input ID $ date : ANYDTDTE21.;
format date mmddyy10.
run;
I do not trust SAS when we ask it to guess
data have;
input dates anydtdte21.;
format dates mmddyy10.;
cards;
1/1/2000
1/15/2000
12/1/2000
12/12/2000
;
When i add in the 21 to the informat, it throws off the other variables in the text file. It is a text file with several variables separated by a '|', all with varying lengths, if that makes a difference.
Sorry , just read the 10 bytes as max
data have1;
input dates anydtdte10.;
format dates mmddyy10.;
cards;
1/1/2000
1/15/2000
12/1/2000
12/12/2000
;
In your very code, you could use a modified list input using an informat than a formatted input and let : colon format modifier to perform the task of not reading any chars once a delimiter is reached/found.
I.e : ANYDTDTE /*notice the colon*/
Data Sample;
Infile 'File_1.txt' dlm='|' firstobs=2 truncover;
input ID $ date : ANYDTDTE21.;
format date mmddyy10.
run;
This worked - THANK YOU!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.