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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

 

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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
;
crockerm12
Calcite | Level 5

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.

novinosrin
Tourmaline | Level 20

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
;
novinosrin
Tourmaline | Level 20

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;

 

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1251 views
  • 0 likes
  • 2 in conversation