Writing a file with PROC SQL
It's hard to think of a good practical application for this code, but maybe one will come up. It shows the use of the file information functions in PROC SQL to write a flat file.
data test;
input @1 value $8.;
cards;
abc
defg
hijklmno
;;;;
proc sql;
select F.filename_rc,
F.file_id,
D.value,
fput (f.file_id, 'value=' || value) as fput_rc,
fwrite(f.file_id) as fwrite_rc
from
(select filename('myfile', 'c:\temp\myfile.txt') as filename_rc,
fopen('myfile', 'O', 256, 'v') as file_id
from test (obs=1)
) as F
right join
test as D
on 1=1
;
quit;
data _null_;
infile 'c:\temp\myfile.txt';
input;
put 'INFO: myfile.txt: ' _infile_;
run;
prints in the log:
NOTE: The infile 'c:\temp\myfile.txt' is:
File Name=c:\temp\myfile.txt,
RECFM=V,LRECL=256
INFO: myfile.txt: value=abc
INFO: myfile.txt: value=defg
INFO: myfile.txt: value=hijklmno
NOTE: 3 records were read from the infile 'c:\temp\myfile.txt'.
The minimum record length was 14.
The maximum record length was 14.

0 Comments:
Post a Comment
<< Home