FOPTNAME Function

Returns the name of an item of information about an external file.

Category:External Files
Restriction:This function is not supported in a DATA step that runs in CAS.

Syntax

FOPTNAME(file-id, nval)

Required Arguments

file-id

is a numeric variable that specifies the identifier that was assigned when the file was opened, generally by the FOPEN function.

nval

is a numeric constant, variable, or expression that specifies the number of the information item.

Details

General Information

FOPTNAME returns a missing or null value if an invalid argument to FOPTNAME is used.

For all available platforms, the number, value, and type of information items that are available vary.

Linux: Available Information Items

The following table shows the information items that correspond to the nval values for single and concatenated files under Linux operating environments.

Information Items for Files under Linux

nval

Single File

Pipe Files

Concatenated Files

1

Filename

PIPE command

Filename

2

Owner name

File list

3

Group name

Owner name

4

Access permission

Group name

5

Last Modified

Access permissions

6

File size (bytes)

File size (bytes)

Examples

Example 1: Retrieving File Information Items and Writing Them to the Log

This example retrieves the system-dependent file information items that are available and writes them to the log:

%macro test;                                                                                                                            
 %let filrf=myfile;                                                                                                                     
 %let rc=%sysfunc(filename(filrf, physical-filename));                                                                                  
 %let fid=%sysfunc(fopen(&filrf));                                                                                                      
 %let infonum=%sysfunc(foptnum(&fid));                                                                                                  
  %do j=1 %to &infonum;                                                                                                                 
   %let name=%sysfunc(foptname(&fid, &j));                                                                                              
   %let value=%sysfunc(finfo(&fid, &name));                                                                                             
   %put File attribute &name equals &value;                                                                                             
  %end;                                                                                                                                 
 %let rc=%sysfunc(fclose(&fid));                                                                                                        
 %let rc=%sysfunc(filename(filrf));                                                                                                     
%mend test;                                                                                                                             
                                                                                                                                        
%test 

Example 2: Creating a Data Set with Names and Values of File Attributes

This example creates a data set that contains the name and value of the available file attributes:

data fileatt;
   length name $ 20 value $ 40;
   drop rc fid j infonum;
   rc=filename("myfile", "physical-filename");
   fid=fopen("myfile");
   infonum=foptnum(fid);
   do j=1 to infonum;
      name=foptname(fid, j);
      value=finfo(fid, name);
      put 'File attribute ' name 
       'has a value of ' value;
      output;
   end;
   rc=filename("myfile");
run;

Example 3: File Attributes When Using the Pipe Device Type under Linux

The following example creates a data set that contains the NAME and VALUE attributes returned by the FOPTNAME function when you are using pipes under Linux:

data fileatt;
   length name $ 30 value $ 40;
   drop fid j infonum;
   filename mypipe pipe 'LINUX-command';
   fid=fopen("mypipe", "s");
   infonum=foptnum(fid);
   do j=1 to infonum;
      name=foptname(fid, j);
      value=finfo(fid, name);
      put 'File attribute' name 'has a value of ' value;
      output;
   end;
run;

SAS writes the following output to the log:

SAS Log

File attribute Pipe Command has a value of UNIX-command

Linux-command is the Linux command or program where you are piping your output or where you are reading your input. This command or program must be either fully qualified or defined in your PATH environment variable.

See Also

Last updated: September 14, 2026