Help using Base SAS procedures

Reading in fields from a txt file

Super Contributor
Posts: 256

Reading in fields from a txt file

I'm reading in a file with loads of fields from a txt file. I'm having a couple of problems with the formatting

One of the fields is a date field with length 10 in the format 01/01/2010 but it also contains blanks where the date missing.

Here is my code




EXPIRY_DATE ddmmyy10.

Comm  17.2



EXPIRY_DATE ddmmyy10.

Comm 17.2



To allow for the blanks, do I need to read it in as a character and then create a new variable with the correct format using sas code.

Also, is there a way to convert to sasdate in the input statement?

One of the other fields, Comm is length 17 in the txt file (including the decimal point) and had two decimal places. Is the above format correct? ie is the 17 in 17.2 the total length of the field including decimal points and .2 the number of decimal places?

Super User
Posts: 6,928

Re: Reading in fields from a txt file

Do not use formats in the input statements, because formatted input ignores the delimiter,

Specify the informats with an INFORMAT statement and then use list input without formats.

Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,071

Re: Reading in fields from a txt file

In addition to KurtBremser's suggestion, also note that the 17.2 informat might be incorrect.  You might be better off with an informat of 17.

The difference occurs when the incoming data does not contain a decimal point.  If the incoming data contains "12345", for example:

"12345" with 17. informat ==> 12345

"12345" with 17.2 informat ==> 123.45

As an informat, 17.2 looks for decimal points and inserts them when the incoming string does not contain a decimal point.

Finally, note that you may not be able to store exactly a numeric that contains 16 significant digits.  You might lose a little precision from the end of the value.

Good luck.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation