Question

I have a variable length, quite ugly reporting file that I am trying to read into SAS. When reading file records, I am finding that spaces on are being automatically trimmed from the left side of the file. This is making it harder to compare the original file to what is in my data step. How do I read the file without doing an automatic trim.

Code for reading file

Data Test;
  Infile myFile lrecl=200 firstobs=1 pad;
  length line $135;

  Input line $ 1 - 135;

Run;

Sample File, spaces replaced by _ for visibility

Num___Transaction__Comment________________________________
1_____Foo__________This_is_a_comment_about_a_transaction__
___________________foo._Line_breaks_are_fun.
2_____Bar__________Blagh_Blagh
3_____Bar__________Blagh_Blagh
4_____Foo__________Foo_transactions_have_more_comments_so
___________________they_are_harder_to_read.

Output Data Set, spaces replaced by _ for visibility

line
-----
1_____Foo__________This_is_a_comment_about_a_transaction__
foo._Line_breaks_are_fun.
2_____Bar__________Blagh_Blagh
3_____Bar__________Blagh_Blagh
4_____Foo__________Foo_transactions_have_more_comments_so
they_are_harder_to_read.
Was it helpful?

Solution

You want to use the $CHARn. informat to preserve leading blanks, so:

Data Test;
  Infile myFile lrecl=200 firstobs=1 pad;
  length line $135;

  Input line $char135.;

Run;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top