07-19-2018 06:02 AM
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 :-
INPUT line $ 1-35;
CREATE TABLE final(data char(480));
INSERT INTO final(data) select line FROM readFile;
PROC REPORT DATA=final NOHEADER;
FILNAME zout '/home/output/out.txt';
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');
if eof then
rc = fclose(fid);
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.
07-19-2018 06:20 AM
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;
07-19-2018 07:33 AM
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.