BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

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

DATA PC ;

  INFILE PC DLM =',' DSD MISSOVER DSD LRECL = 2000 ;

FORMAT

EXPIRY_DATE ddmmyy10.

Comm  17.2

;

input

EXPIRY_DATE ddmmyy10.

Comm 17.2

;

run;

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?

2 REPLIES 2
Kurt_Bremser
Super User

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.

Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1595 views
  • 0 likes
  • 3 in conversation