DATA Step, Macro, Functions and more

Import text file with string longer than 32767

Accepted Solution Solved
Reply
Super Contributor
Posts: 398
Accepted Solution

Import text file with string longer than 32767

Hello,

 

I have a file with varying row lengths.  I only want one variable in my table that has each full fow in it.

 

This is what I have so far and it doesn't bring in the full row

 

data temp ;		
	infile file1 lrecl=390000 ; 
	input x $ ;	
run ;

I know it's something simple, but I can't seem to figure it out.

 

Thank you


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Respected Advisor
Posts: 3,777

Re: Import text file with string longer than 32767

[ Edited ]

I was unable to modify my reply, could only post the code. You can't have a variable in SAS longer than 32767 so you will need to read each line into more than one variable. My example shows how that can be done. Change 40 to something larger up to 32767. The array diminsion will need to change also to suite your needs.

 

It would be helpful to know what you would do with the record as variable(s).

View solution in original post


All Replies
Respected Advisor
Posts: 3,777

Re: Import text file with string longer than 32767

[ Edited ]
filename FT15F001 temp;
data lines;
   infile FT15F001 truncover;
   array part[3] $40.;
   input (part[*])($char40.);
   parmcards;
this is the data line this is the line this is the data line 
this is the data line this is the data line this is the data line this is the data line 
this is the data line this is the data line this is the data line 
;;;;
   run;

 

This example shows how you might read each recored in a file into a number of variables up to 32767 in length. 

Super Contributor
Posts: 398

Re: Import text file with string longer than 32767

thank you data_null_,

 

I need each row to come in as a single row.  The lengths of each row vary and they are larger then 32767. 

Is that the max length of a character variable field?

Solution
‎09-25-2015 06:23 AM
Respected Advisor
Posts: 3,777

Re: Import text file with string longer than 32767

[ Edited ]

I was unable to modify my reply, could only post the code. You can't have a variable in SAS longer than 32767 so you will need to read each line into more than one variable. My example shows how that can be done. Change 40 to something larger up to 32767. The array diminsion will need to change also to suite your needs.

 

It would be helpful to know what you would do with the record as variable(s).

Super Contributor
Posts: 398

Re: Import text file with string longer than 32767

Thank you so much.

 

I need to add more data to the end of each row for use in another process.

 

That did it.  I tested it with one row and I was able to split it up and add the data to the end then put it into another text file.

 

Thank you

Respected Advisor
Posts: 3,777

Re: Import text file with string longer than 32767

[ Edited ]

I thought you might say that.  To copy records and add data to the end you don't need to create a SAS data set of the input file.  You can do everything in one DATA _NULL_ ...

 

data _null_;
   infile FT15F001 lrecl=%sysevalf(32767*2); /*LRECL larger than 32767 means no _INFILE_ variable*/
   input;
   set sashelp.class(obs=3);
   file log ls=256; /*You will use FILENAME and LRECL appropriate to your application*/
   put _infile_ +1 'New at end ' (_all_)(=); /*_INFILE_ is not a variable but a put statement directive*/
   parmcards;
this is the data line this is the line this is the data line 
this is the data line this is the data line this is the data line this is the data line 
this is the data line this is the data line this is the data line 
;;;;
   run;

Capture.PNG

Super Contributor
Posts: 398

Re: Import text file with string longer than 32767

I like that approach better.   I like that it is all in one data step.

 

Thank you again

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 936 views
  • 1 like
  • 2 in conversation