I have a table with 100 variables (I copied here only 8 for the example), and I want to convert it into a macro in which I can only insert the first variable number (1) and the last one (100) and run this table with only one or two rows inside it (instead of 100). Does anyone know how to do that?
CTABLES
/VLABELS VARIABLES=Loop1_a_01 var1 DISPLAY=DEFAULT
/TABLE var1 [C][ROWPCT.COUNT F40.0] +
var2 [C][ROWPCT.COUNT F40.0] +
var3 [C][ROWPCT.COUNT F40.0] +
var4 [C][ROWPCT.COUNT F40.0] +
var5 [C][ROWPCT.COUNT F40.0] +
var6 [C][ROWPCT.COUNT F40.0] +
var7 [C][ROWPCT.COUNT F40.0] +
var8 [C][ROWPCT.COUNT F40.0] BY Loop1_a_01
/CATEGORIES VARIABLES=Loop1_a_01 EMPTY=INCLUDE
/CATEGORIES VARIABLES=var5 ORDER=A KEY=VALUE
EMPTY=INCLUDE
/TITLES TITLE= 'TV'
.
Since you are using the same statistics for all the variables, you can simplify the ctables code by factoring out the repeated statistics, e.g., /TABLE (var1+var2+...)[ROWPCT.COUNT F40.0] BY ... Now, if you want to do something like including all the variables in a dataset whose names look like varnn, you can automate this by using the SPSSINC SELECT VARIABLES extension command to generate a macro. For example
SPSSINC SELECT VARIABLES MACRONAME="!myvars"
/PROPERTIES PATTERN = "var\d+"
/OPTIONS SEPARATOR="+".
CTABLES /TABLE (!myvars)[....
It is possible to write a more complex macro to generate !myvars, but if you need to impose extra logic, generating it with Python programmability would be much easier.