how to read this .txt file into SAS

Accepted Solution Solved
Reply
Super Contributor
Posts: 267
Accepted Solution

how to read this .txt file into SAS

Hello,

 

I have a .txt file abc.txt:

 

 

 

 /*Program name newcode.sas*/
/*This SAS program will print sashelp.class*/
proc print data=sashelp.class;
run;
data a;
"set sashelp.class;
run;

 

 

 

How I can read it in to SAS dataset?

Thanks


Accepted Solutions
Solution
‎05-15-2017 12:07 PM
Super User
Posts: 9,311

Re: how to read this .txt file into SAS

Posted in reply to GeorgeSAS

The obvious question here is, of course: what are you planning to do with SAS code in a dataset?

 

Reading just text into a dataset is simple:

data textdata;
infile "textfile" truncover;
input textline $100.;
run;

After that step has run, check for maximum length of textline. If that is equal to the defined length, increase the format in the input statement; if length exceeds 254, als set a corresponding lrecl in the infile statement. Once you find that max(length(textline)) is smaller than the defined length, you can be sure that all text is read.

With large length values and nobs > several thousand, use the compress=yes option on the dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
PROC Star
Posts: 7,989

Re: how to read this .txt file into SAS

Posted in reply to GeorgeSAS

@GeorgeSAS,

 

I think this is related to your last question. Lookup %include

 

Art, CEO, AnalystFinder.com

 

Solution
‎05-15-2017 12:07 PM
Super User
Posts: 9,311

Re: how to read this .txt file into SAS

Posted in reply to GeorgeSAS

The obvious question here is, of course: what are you planning to do with SAS code in a dataset?

 

Reading just text into a dataset is simple:

data textdata;
infile "textfile" truncover;
input textline $100.;
run;

After that step has run, check for maximum length of textline. If that is equal to the defined length, increase the format in the input statement; if length exceeds 254, als set a corresponding lrecl in the infile statement. Once you find that max(length(textline)) is smaller than the defined length, you can be sure that all text is read.

With large length values and nobs > several thousand, use the compress=yes option on the dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 174 views
  • 2 likes
  • 3 in conversation