BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8


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;

1 REPLY 1
Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1 reply
  • 1286 views
  • 0 likes
  • 2 in conversation