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;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 994 views
  • 0 likes
  • 2 in conversation