DATA Step, Macro, Functions and more

Close a file in data set

Reply
Contributor
Posts: 21

Close a file in data set

Hi, I have the following code in which a file is open in write mode.

filename write "&batchfiledir\&batchname.sas";                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                
data _null_;                                                                                                                                                                                                                                                    
file write;                                                                                                                                                                                                                                                     
set _BatchfileData_ end=eof;                                                                                                                                                                                                                                    
length incstmnt $ 1000;                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                
if _n_=1 and lengthn(trim("&desc"))>0                                                                                                                                                                                                                           
  then put '/* Batch description: ' "&desc" ' */' /;                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                
incstmnt=cats("&tmpprotpath\", files);                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                
info=symget("mapunixdir_info");                                                                                                                                                                                                                                 
getunixdir=strip(scan(info,1,":"));                                                                                                                                                                                                                             
getwindir=strip(scan(info,2,":"));                                                                                                                                                                                                                              
incstmnt=tranwrd(incstmnt ,trim(getwindir),trim(getunixdir));                                                                                                                                                                                                   
incstmnt=translate(incstmnt,'/','\');                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                
  incstmnt=catt('%include "', incstmnt , '";' );                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                
  put incstmnt ;                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                
run;                                                                                                                                                                                                                                                            

I am getting I/O error since this file is open in write mode and is not closed. Please suggest on ways to close this file.

Super Contributor
Posts: 345

Betreff: Close a file in data set

Adding

filename write clear;

after run-statement should solve the issue.

 

You may want to add another period in your first filename-statement to create a properly named file:

filename write "&batchfiledir\&batchname..sas";  

The first period is the separator between macro variable an following text and automatically ommitted.

Super User
Posts: 11,343

Re: Close a file in data set

When you receive an error it is very helpfule to post the log and the entire text of the error message.

 

By any chance do you have any calls to the FOPEN function in your program elsewhere from the code you posted?

Ask a Question
Discussion stats
  • 2 replies
  • 191 views
  • 0 likes
  • 3 in conversation