BookmarkSubscribeRSS Feed
yadaw
Fluorite | Level 6

Hi all,

 

I have one file details.txt with data:-

ajay    manager    account    45000
sunil   clerk      account    25000
varun   manager    sales      50000
amit    manager    account    47000
tarun   peon       sales      15000
deepak  clerk      sales      23000
sunil   peon       sales      13000
satvik  director   purchase   80000

 I want output file out.txt same as input file details.txt but want spaces after datas to make all rows of 480bytes long.

 To achieve this i have did :-

=============================================================================================

 

DATA readFile;

      INFILE '/home/inputFile/details.txt';

      INPUT line $ 1-35;

RUN;

 

PROC sql;

      CREATE TABLE final(data char(480));

      INSERT INTO final(data) select line FROM readFile;

QUIT;

 

PROC REPORT DATA=final NOHEADER;

RUN;
FILNAME zout '/home/output/out.txt';

 

DATA _null_;
  SET final end=eof;          * set the dataset final ;

  RETAIN fid 0;

  if _n_ eq 1 then
     fid = fopen('zout','O');

  if fid gt 0 then do;
    rc = fput(fid,data);          * data is a variable of dataset final ;
    rc = fwrite(fid,'P');
  end;

  if eof then
     rc = fclose(fid);
run;

FILNAME zout;

 

=============================================================================================

 

but in output file i got each row of length 256 bytes but i want it 480 bytes.

 

Thanks in advance...

Please provide me a solution to achieve my desired output.

 

 

2 REPLIES 2
Kurt_Bremser
Super User

Use the lrecl= option in the filename statement to increase the buffer size (default is 256).

But why don't you do

data _null_;
infile '/home/inputFile/details.txt' truncover;
file '/home/output/out.txt' lrecl=480;
input line $480.;
put line $480.;
run;

?

andreas_lds
Jade | Level 19

Most times reading the documentation is enlightening. The file-statment has an option called "pad" controlling "whether records written to an external file are padded with blanks to the length that is specified in the LRECL= option."

 

So you need the options lrecl=480 and pad in your file-statement. Instead of pad you could use recfm=f.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 1475 views
  • 1 like
  • 3 in conversation