DATA Step, Macro, Functions and more

Proc import from a flat file

Reply
Super Contributor
Posts: 647

Proc import from a flat file


I'm trying to import a flat file using proc iimport defining the informats and formats and input variables. But in the input file, instead of having a single line per record, two lines make a single record. this is throwing off the data alignment. As shown below:

*","01","8","","","","","","","","","","","","","AbcRgH5172675","    ","1","","A","02","","01","000","p","▒ ","UK","","

","","N","0NNNN","0000000711","","","","","","","","","","","","","","","","","","","N","","","","","",""

this is causing an issue when reading the data.there are a ttoal of 55 variables. I'm using the following procedure:

  data a;

infile '/home/usr/test_file' dlm=',' dsd MISSOVER   lrecl=534; 

       informat STREET_AD_1_TX $35.;

       informat STREET_AD_2_TX   $35.;

       informat AD_CITY_NM $30.;

       informat AD_STATE_CD $2.;

       informat AD_ZIP_CD $9.;

format  STREET_AD_1_TX $35.;

format STREET_AD_2_TX   $35.;

format AD_CITY_NM $30.;

format AD_STATE_CD $2.;

      format AD_ZIP_CD $9.;

input

STREET_AD_1_TX $

STREET_AD_2_TX  $

AD_CITY_NM $

AD_STATE_CD $

AD_ZIP_CD $

;

run;

Super User
Super User
Posts: 6,500

Re: Proc import from a flat file

If all of the variables are present then just removing the MISSOVER option should let SAS move to the next line to find the other fields.  But if some of the records are missing some of the fields (ie there aren't enough commas) then this will cause SAS to get out of sync.

If the same number of fields are always on the first line then just put a / after the last field name in the first line in your INPUT statement.

If instead the issue is that some of the fields contain embedded end-of-line characters so that records are being split then you have a bigger problem.

Ask a Question
Discussion stats
  • 1 reply
  • 213 views
  • 0 likes
  • 2 in conversation