Dear reader, I am asking for help...
I am trying to import a TXT file with just text, but also ; : TAB etc..
I want to get the full file imported- just one variable, the file has 1861 rows but it only imports 20 of them
This is the code for importing:
PROC IMPORT DATAFILE="C:\Output\log.txt"
OUT=LOGFILE
DBMS=TAB REPLACE;
GETNAMES=NO;
RUN;
My LOG:
NOTE: WORK.LOGFILE data set was successfully created.
NOTE: The data set WORK.LOGFILE has 20 observations and 1 variables.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.08 seconds
cpu time 0.04 seconds
Why are 20 lines imported and what can I best do?
I prefer PROC IMPORT...
Many thanks!
But I prefer to use data step ,that is simple and easy,if you only want ONE variable in dataset.
data x;
infile "C:\temp\a\log.txt" termstr=crlf length=len ignoredoseof;
input x $varying1000. len;
run;
PROC IMPORT is a guessing procedure. It guesses how the fields are separated, and in this case it guessed wrong.
You can read the data in a DATA step, where you use the INFILE statement with the DLM= option. The DLM= option allows you to specify more than one different delimiters that the file uses. https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lestmtsref/n1rill4udj0tfun1fvce3j401plo.htm#n14rj...
In fact, PROC IMPORT will create (incorrect) code for you, look in the log. You should be able to modify the code so that the DATA step reads the data properly.
Why did you bother to attach that log? There is NO code that imports any txt file. Everything I see that calls proc import is for XLSX.
Unless asked only include log for pieces of code that you have a question about. Since there is nothing in that log with
PROC IMPORT DATAFILE="C:\Output\log.txt" it is useless. And the snippet that you show is not the complete log because if you use Proc Import with a Tab delimited file then there will be generated data step code.
Causes for fewer observations than you expect could be the file source uses a different end of line marker.
Which in a data step you use the INFILE statement to set the TERMSTR= option to see if that is the case. TERMSTR=CRLF for Windows source files, TERMSTR=LF for Unix Linux and derivitives and TERMSTR=CR for some other sources.
You have EOF(end of file) character at 21th row, therefore sas stop reading file when running into it .
Add option IGNOREDOSEOF to ignore EOF character to read this fill all.
filename x "C:\temp\a\log.txt" termstr=crlf ignoredoseof;
PROC IMPORT DATAFILE=x
OUT=LOGFILE
DBMS=TAB REPLACE;
GETNAMES=NO;
guessingrows=max;
RUN;
But I prefer to use data step ,that is simple and easy,if you only want ONE variable in dataset.
data x;
infile "C:\temp\a\log.txt" termstr=crlf length=len ignoredoseof;
input x $varying1000. len;
run;
Thank you so much Amir, it works !
Greetings, Johan
sorry, not Amir but Mr. Sharp...
Hi,
I'm not sure that I fully understand your requirement, there is mention of Tab characters in the data and that you only want one variable for the whole file, but Tab is in your proc import code too; maybe I'm missing something.
I see that you've said you prefer proc import, but as you are having problems with it, you can see if a data step alternative works for, e.g., as per the below untested code (you can change the log_record length if necessary):
data logfile;
infile "C:\Output\log.txt" truncover;
input log_record $char256.;
run;
Thanks & kind regards,
Amir.
You don't need to IMPORT text files since SAS can just READ a text file.
The only reason to use PROC IMPORT to read a delimited file is if you want it to try to GUESS how to read it.
And if you don't have a delimited file there is nothing that it can GUESS for you.
So just read the file yourself with a DATA step.
Read this log file with a DATA step and use the proper line termination string:
data log;
infile "log.txt" termstr=LF truncover;,
input line $256.;
run
LF is for text files originating from a UNIX environment. For Windows, use CRLF.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: