The OPTMODEL Procedure

FILE Statement

FILE file-specification [LRECL=value];

The FILE statement selects the current output file for the PUT statement. By default PUT output is sent to the SAS log. Use the FILE statement to manage a group of output files. The specified file is opened for output if it is not already open. The output file remains open until it is closed with the CLOSEFILE statement.

File-specification names the output file. It can use any of the following forms:

'external-file'
specifies the physical name of an external file in quotation marks. The interpretation of the filename depends on the operating environment.

file-name
specifies the logical name associated with a file by the FILENAME statement or by the operating environment. The names PRINT and LOG are reserved to refer to the SAS listing and log files, respectively.

Note: Details about the FILENAME statement can be found in SAS Language Reference: Dictionary.

(expression)
specifies an expression that evaluates to a string that contains the physical name of an external file.

The LRECL option sets the line length of the output file. If the option is omitted, then the line length defaults to 256 characters. The LRECL option is ignored if the file is already open or if the PRINT or LOG file is specified.

In SAS/OR release 9.2, if the LRECL= option is omitted, then the default line length is defined by the value of the SAS LRECL system option. The default value for the SAS LRECL system option is 256. In SAS/OR releases before 9.2, the default line length is 256.

The LRECL value can be specified in these forms:

integer
specifies the desired line length.

identifier-expression
specifies the name of a numeric parameter that contains the length.

(expression)
specifies a numeric expression in parentheses that returns the line length.

The LRECL value cannot exceed the largest four-byte signed integer, which is 2^{31} - 1.

The following example shows how to use the FILE statement to handle multiple files:

  
    proc optmodel; 
       file 'file.txt' lrecl=80;   /* opens file.txt     */ 
       put 'This is line 1 of file.txt.'; 
       file print;                  /* selects the listing */ 
       put 'This goes to the listing.'; 
       file 'file.txt';            /* reselects file.txt */ 
       put 'This is line 2 of file.txt.'; 
       closefile 'file.txt';       /* closes file.txt    */ 
       file log;                    /* selects the SAS log */ 
       put 'This goes to the log.'; 
  
       /* using expression to open and write a collection of files */ 
       str ofile; 
       num i; 
       num l = 40; 
       do i = 1 to 3; 
          ofile = ('file' || i || '.txt'); 
          file (ofile) lrecl=(l*i); 
          put ('This goes to ' || ofile); 
          closefile (ofile); 
       end;
 

The following code illustrates the usefulness of using a logical name associated with a file by FILENAME statement:

  
    proc optmodel; 
       /* assigns a logical name to file.txt */ 
       /* see FILENAME statement in */ 
       /* SAS Language Reference: Dictionary */ 
       filename myfile 'file.txt' mod; 
  
       file myfile; 
       put 'This is line 3 of file.txt.'; 
       closefile myfile; 
       file myfile; 
       put 'This is line 4 of file.txt.'; 
       closefile myfile;
 

Notice that the FILENAME statement opens the file referenced for append. Therefore, new data are appended to the end every time the logical name, myfile, is used in the FILE statement.

Previous Page | Next Page | Top of Page