Functions and CALL Routines |
Category: | External Files |
Syntax | |
Arguments | |
Details | |
Examples | |
See Also |
Syntax |
FPUT(file-id,cval) |
is a numeric variable that specifies the identifier that was assigned when the file was opened, generally by the FOPEN function.
is a character constant, variable, or expression that specifies the file data.
Details |
FPUT returns 0 if the operation was successful, 0 if it was not successful. The number of bytes moved to the FDB is determined by the length of the variable. The value of the column pointer is then increased to one position past the end of the new text.
Note: 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.
Examples |
This example assigns the fileref MYFILE to an external file and attempts to open the file in APPEND mode. If the file is opened successfully, indicated by a positive value in the variable FID, it moves data to the FDB using FPUT, appends a record using FWRITE, and then closes the file. Note that in a macro statement you do not enclose character strings in quotation marks.
%macro ptest; %let filrf=myfile; %let rc=%sysfunc(filename(filrf,test.txt)); %let fid=%sysfunc(fopen(&filrf,a)); %if &fid > 0 %then %do; %let rc=%sysfunc(fread(&fid)); %let mystring=This is some data.; %let rc=%sysfunc(fput(&fid,&mystring)); %let rc=%sysfunc(fwrite(&fid)); %let rc=%sysfunc(fclose(&fid)); %end; %else %put %sysfunc(sysmsg()); %let rc=%sysfunc(filename(filrf)); %put return code = &rc; %mend; %ptest;
SAS writes the following output to the log:
return code = 0
See Also |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.