Get all string or all numeric variables
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | * Define a macro which will give us the names of the string variables as well as the list of numeric variables contained in the list given to the macro; after running the macro, the macros !num yields the list of numeric variables and the macro !str yields the list of numeric variables * Posted to SPSSX-L list by rlevesque@videotron.ca on 2001/07/18. GET FILE='c:\\Program Files\\SPSS\\employee data.sav'. *//////////////////////. DEFINE !VarType (!POS=!CMDEND) SAVE OUTFILE='c:\\temp\\temp.sav'. MATCH FILES FILE=* /KEEP=!1. N OF CASES 1. SET ERRORS=no. DO REPEAT v=!1. COMPUTE v=1. END REPEAT. SET ERRORS=yes. FLIP. IF MISSING(var001) var001=0. SORT CASES BY var001. MATCH FILES FILE=* /BY var001 /LAST=last. DO IF $CASENUM=1. WRITE OUTFILE="c:\\temp\\string vars.sps" /"DEFINE !str()". WRITE OUTFILE="c:\\temp\\num vars.sps" /"DEFINE !num()". END IF. DO IF var001 = 0. WRITE OUTFILE="c:\\temp\\string vars.sps" /" " case_lbl. ELSE. WRITE OUTFILE="c:\\temp\\num vars.sps" /" " case_lbl. END IF. DO IF last and var001=0. WRITE OUTFILE="c:\\temp\\string vars.sps" /"!ENDDEFINE.". ELSE IF last and var001=1. WRITE OUTFILE="c:\\temp\\num vars.sps" /"!ENDDEFINE.". END IF. EXECUTE. INCLUDE FILE="c:\\temp\\string vars.sps". INCLUDE FILE="c:\\temp\\num vars.sps". GET FILE='c:\\temp\\temp.sav'. !ENDDEFINE. *//////////////////////. ** Example of use of the macro. !VarType id TO jobcat. * List string variables. LIST !str. * List numeric variables. LIST !num. ***** Note: If you use the macro !str and !num within a macro, use the expressions such as !EVAL(!str) and !EVAL(!num) instead of just the macro names. |
Related pages
...
Navigate from here