Functions and CALL Routines |
Writes a record to an external file.
-
file-id
-
is a numeric variable that specifies the
identifier that was assigned when the file was opened, generally by the FOPEN
function.
-
cc
-
is a character constant, variable, or expression
that specifies a carriage-control character:
blank |
starts the record on a new line. |
0 |
skips one blank line before a new
line. |
- |
skips two blank lines before a new
line. |
1 |
starts the line on a new page. |
+ |
overstrikes the line on a previous
line. |
P |
interprets the line as a computer
prompt. |
= |
interprets the line as carriage control
information. |
all else |
starts the line record on a new line. |
FWRITE returns 0 if the operation was
successful,
0 if it was not successful. FWRITE moves text from the File
Data Buffer (FDB) to the external file. In order to use the carriage control
characters, you must open the file with a record format of P
(print format) in FOPEN.
Note: When you use the update mode, you must
execute FREAD before you execute FWRITE. You cannot write a new record in
place of the current record if the new record has a length that is greater
than the current record. ![[cautionend]](../../../../common/63294/HTML/default/images/cautend.gif)
This example assigns the fileref MYFILE to an external
file and attempts to open the file. If the file is opened successfully, it
writes the numbers 1 to 50 to the external file, skipping two blank lines.
Note that in a macro statement you do not enclose character strings in quotation
marks.
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
physical-filename));
%let fid=%sysfunc(fopen(&filrf,o,0,P));
%do i=1 %to 50;
%let rc=%sysfunc(fput(&fid,
%sysfunc(putn(&i,2.))));
%if (%sysfunc(fwrite(&fid,-)) ne 0) %then
%put %sysfunc(sysmsg());
%end;
%let rc=%sysfunc(fclose(&fid));
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.