FINFO Function: Windows

Returns the value of an information item for an external file.
Category: External Files
Windows specifics: available info-items
See: FINFO Function in SAS Functions and CALL Routines: Reference

Syntax

FINFO(file-id, info-item)

Required Arguments

file-id
specifies the identifier that was assigned when the file was opened, generally by the FOPEN function.
info-item
specifies the name of the file information item to be retrieved. This item is a character value. Info-item is either a variable that contains a file information name or the file information name that has been enclosed in quotation marks.
info-item for disk files can be one of these file information items:
  • Create Time: ddmmmyyyy:hh:mm:ss
    Note: The Create Time date/time information item will be localized to the site's locale. The date/time format might appear slightly different in the locale.
  • Last Modified: ddmmmyyyy:hh:mm:ss
  • Filename
  • File size (bytes)
  • RECFM
  • LRECL
info-item for pipe files can be one of these file information items:
  • Unnamed pipe access device
  • PROCESS
  • RECFM
  • LRECL

Details

The FINFO function returns the value of a system-dependent information item for an external file that was previously opened and assigned a file-id by the FOPEN function. FINFO returns a blank if the value given for info-item is invalid.

Example: Obtaining File Information

data a;
/* Does fileref "curdirfl" exist?  No = 0 */
rc=fexist ("curdirfl");
put;
put "Fileref curdirfl exist? rc should be 0 (no); " rc=;
/* assign fileref */
rc=filename("curdirfl", "c:\tmp333");
/* RC=0 indicates success in assigning fileref */
put "Fileref assigned - rc should be 0; " rc=;
rc=fexist ("curdirfl");
/* Does file which "curdirfl" points to exist?  No = 0 */
/* Assigning a fileref doesn't create the file. */
put "File still doesn't exist - rc should be 0; " rc=;
rc=fileref ("curdirfl");
/* Does fileref "curdirfl" exist?  */
/* Negative means fileref exists, but file does not */
/* Positive means fileref does not exist            */
/* Zero means both fileref and file exist           */
put "Fileref now exists - rc should be negative; " rc=;
put;
/* Does the file that the fileref points to exist?  Should be no. */
if ( fileexist ("./tmp333") ) then
    /* if it does, open it for input */
      do;
        put "Open file for input";
        fid=fopen ("curdirfl", "i") ;
      end;
   else       /* most likely scenario */
      do;
        put "Open file for output";
        fid=fopen ("curdirfl", "o");
      end;
/* fid should be non-zero.  0 indicates failure. */
put "File id is: " fid=;
numopts = foptnum(fid);
put "Number of information items should be 6; " numopts=;
do i = 1 to numopts;
optname = foptname (fid,i);
put i= optname=;
optval  = finfo (fid, optname);
put optval= ;
end;
rc=fclose (fid);
rc=fdelete ("curdirfl");
put "Closing the file, rc should be 0; "
rc=; run;
The Resulting SAS Log
NOTE: PROCEDURE PRINTTO used (Total process time):
      real time           0.36 seconds
      cpu time            0.00 seconds
291  data a;
292
293  /* Does fileref "curdirfl" exist?  No = 0 */
294
295  rc=fexist ("curdirfl");
296  put;
t297  put "Fileref curdirfl exist? rc should be 0 (no); " rc=;
298
299  /* assign fileref */
300
301  rc=filename("curdirfl", "c:\tmp333");
302
303  /* RC=0 indicates success in assigning fileref */
304
305  put "Fileref assigned - rc should be 0; " rc=;
306  rc=fexist ("curdirfl");
307
308  /* Does file which "curdirfl" points to exist?  No = 0 */
309  /* Assigning a fileref doesn't create the file. */
310
311  put "File still doesn't exist - rc should be 0; " rc=;
312  rc=fileref ("curdirfl");
313
314  /* Does fileref "curdirfl" exist?  */
315  /* Negative means fileref exists, but file does not */
316  /* Positive means fileref does not exist            */
317  /* Zero means both fileref and file exist           */
318
319  put "Fileref now exists - rc should be negative; " rc=;
320  put;
321
322  /* Does the file that the fileref points to exist?  Should be no. */
323
324  if ( fileexist ("./tmp333") ) then
325      /* if it does, open it for input */
326        do;
327          put "Open file for input";
328          fid=fopen ("curdirfl", "i") ;
329        end;
330     else       /* most likely scenario */
331        do;
332          put "Open file for output";
333          fid=fopen ("curdirfl", "o");
334        end;
335
336  /* fid should be non-zero.  0 indicates failure. */
337  put "File id is: " fid=;
338  numopts = foptnum(fid);
339  put "Number of information items should be 6; " numopts=;
340  do i = 1 to numopts;
341  optname = foptname (fid,i);
342  put i= optname=;
343  optval  = finfo (fid, optname);
344  put optval= ;
345  end;
346  rc=fclose (fid);
347  rc=fdelete ("curdirfl");
348  put "Closing the file, rc should be 0; "
349  rc=; run;
Fileref curdirfl exist? rc should be 0 (no); rc=0
Fileref assigned - rc should be 0; rc=0
File still doesn't exist - rc should be 0; rc=0
Fileref now exists - rc should be negative; rc=-20006
Open file for output
File id is: fid=1
Number of information items should be 6; numopts=6
i=1 optname=Filename
optval=c:\tmp333
i=2 optname=RECFM
optval=V
i=3 optname=LRECL
optval=256
i=4 optname=File Size (bytes)
optval=0
i=5 optname=Last Modified
optval=13Mar2007:13:12:23
i=6 optname=Create Time
optval=13Mar2007:13:12:23
Closing the file, rc should be 0; rc=0
NOTE: The data set WORK.A has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.12 seconds
      cpu time            0.09 seconds
350  proc printto; run;

See Also

FOPEN Function in SAS Functions and CALL Routines: Reference