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

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

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

6 REPLIES 6
data_null__
Jade | Level 19
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. 

jerry898969
Pyrite | Level 9

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?

data_null__
Jade | Level 19

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).

jerry898969
Pyrite | Level 9

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

data_null__
Jade | Level 19

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

jerry898969
Pyrite | Level 9

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

 

Thank you again

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 5617 views
  • 2 likes
  • 2 in conversation