BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
podarum
Quartz | Level 8

Hi, when I proc import a raw .txt file, a specific field (name of customer) cuts off at a certain length, other fields remain in their lengths, some longer.. No idea why.  Please help !!

 

Here's my proc import code:

 

proc import out = raw datafile = "S:\Banking\MIS\Reports\Report_&rpt_dt..txt"

 dbms = dlm  replace;

 delimiter = '09'x;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You could add to your PROC IMPORT the following statement.

 

guessingrows=max;

For an extremely large input file, this may cause the processing time to double.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

I think we'd need for you to share a part of this .txt file in order to provide any advice.

 

Also, please remember that PROC IMPORT is a guessing procedure; it guesses at the lengths of fields, and sometimes gets it wrong.

--
Paige Miller
podarum
Quartz | Level 8

Good idea, however I can't due to very sensitive personal information..  Is there a different way?  Can I specify the length in the proc import for that specific field?

PaigeMiller
Diamond | Level 26

You could add to your PROC IMPORT the following statement.

 

guessingrows=max;

For an extremely large input file, this may cause the processing time to double.

--
Paige Miller
ballardw
Super User

@podarum wrote:

Good idea, however I can't due to very sensitive personal information..  Is there a different way?  Can I specify the length in the proc import for that specific field?


Are your column headings that sensitive? Since your question revolver around how the column headings are read that is the import element.

 

Note: if you have a text file, import 1 file. Look in the log and copy the generated data step to the editor and clean up the code.

Then you can may changes such as fixing variable names, types and lengths that will change from Proc Import runs.

Then replace the file name in the INFILE statement and the name of the output data set to read each file.

Now you control the names and content of the SAS data set instead of letting a guessing routine control things.

Tom
Super User Tom
Super User

Don't force SAS to guess what your variables are and how to define them.  Especially if you are going to read the same data layout for many different dates.  When PROC IMPORT guesses the only information it has is the one example file it is currently reading.

 

Write your own data step so that you have control. 

data raw;
  infile "S:\Banking\MIS\Reports\Report_&rpt_dt..txt" firstobs=2 truncover dsd dlm='09'x;
  length firstvar $100 var2 8 lastvar $40 ;
  input firstvar -- lastvar ;
run;

If you really don't know what the variables are you could copy the names from the first line of the file.  Or copy the names that PROC IMPORT generated.

Kurt_Bremser
Super User

Proc import creates a data step which you can find in the log; copy it from there, and adapt it to the real variable attributes. Use it in the future, if you have to read the same structure again.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 2749 views
  • 1 like
  • 5 in conversation