*QUESTION: How can I detect the existence of a file by syntax? *ANSWER: posted to SPSS newsgroup by rlevesque@videotron.ca on 2001/05/15. * First save the following file as "c:\\temp\\isfile.sps". *------------ beginning of "c:\\temp\\isfile.sps". GET FILE='d:\\temp\\mydatafile.sav'. * replace the above with the path and name of the file you wish to check the existence. DEFINE !isfile()'yes'!ENDDEFINE. *------------ end of "c:\\temp\\isfile.sps". ********************. * The first time the following syntax is ran, the file mydata.sav does not exists. ********************. DATA LIST LIST /dummy. BEGIN DATA 1 END DATA. DEFINE !isfile()'no'!ENDDEFINE. INCLUDE 'c:\\temp\\isfile.sps'. STRING mydata(A14). DO IF !isfile='yes'. * File exists. COMPUTE mydata="exists". ELSE. * File does not exists. COMPUTE mydata="does not exist". END IF. EXECUTE. ********************. * Now create the file before to prove the syntax detects its existence. ********************. DATA LIST LIST /dummy. BEGIN DATA 1 END DATA. SAVE OUTFILE='d:\\temp\\mydatafile.sav'. DEFINE !isfile()'no'!ENDDEFINE. INCLUDE 'c:\\temp\\isfile.sps'. STRING mydata(A14). DO IF !isfile='yes'. * File exists. COMPUTE mydata="exists". ELSE. * File does not exists. COMPUTE mydata="does not exist". END IF. EXECUTE.