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;
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.
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.
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?
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.
@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.
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.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.