Choice of include file depends on existence of a given variable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * Say you need to run the file c:\\temp\\mysyntax.sps when a given variable does not exists. * The following syntax checks whether the given variable exists. * NOTE: Before running this syntax, you need to create the file c:\\temp\\mysyntax.sps. * It could contain a single line with a comment ' *This is the mysyntax.sps file'. * Posted to SPSSX-L list on 2001/04/24 by rlevesque@videotron.ca. SET MPRINT=yes. */////////////////////////////. DEFINE !exist (varname=!TOKENS(1)) SAVE OUTFILE='c:\\temp\\temp.sav'. N OF CASES 1. FLIP. IF (!QUOTE(!UPCASE(!varname))=CONCAT('',RTRIM(UPCASE(case_lbl)),'')) exist=1. COMPUTE dummy=1. AGGREGATE /OUTFILE=* /BREAK=dummy /exist = MAX(exist). DO IF ~MISSING(exist). WRITE OUTFILE='c:\\temp\\testvar.sps' /'* Nothing to do, variable exists.'. ELSE. WRITE OUTFILE='c:\\temp\\testvar.sps' /'* Variable does not exist, must include file.' /'INCLUDE FILE=''c:\\temp\\mysyntax.sps''.'. END IF. EXECUTE. GET FILE='c:\\temp\\temp.sav'. INCLUDE FILE='c:\\temp\\testvar.sps'. !ENDDEFINE. */////////////////////////////. GET FILE='c:\\program files\\spss\\employee data.sav'. * Next macro call will NOT include the file mysyntax.sps. !exist varname=educ. GET FILE='c:\\program files\\spss\\employee data.sav'. * Next macro call will INCLUDE the file mysyntax.sps. !exist varname=notexist. |
Related pages
...