BookmarkSubscribeRSS Feed
Arjumand
Calcite | Level 5

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.

2 REPLIES 2
andreas_lds
Jade | Level 19

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.

ballardw
Super User

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?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 864 views
  • 0 likes
  • 3 in conversation