Hey, The FILENAME function executes during DATA step execution, while the FILE statement opens the file before the DATA step begins execution. If you use the FILENAME in the DATA step, the DATA step compiles both the FILENAME function and FILE statement. At this point, no files have been created. Just before the DATA step executes, the fileref StatFile is opened for output (created). The fileref StatFile doesn't exist, so a file named StatFile.dat is created. When the DATA step executes, the FILENAME function executes and creates the fileref StatFile. At this point, it is too late to use this fileref with the FILE statement as the FILE statement has already done its work. Hope this helps, Bago
... View more