| The OPTMODEL Procedure | 
The LRECL value cannot exceed the largest four-byte signed integer, which 
 is   .
.
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.
Copyright © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.