2
votes

I have multiple spss file having multiple number of variables(col1,col2,...col150).I am trying to create a common code for restructure the file using VARSTOCVASES. in this i need to KEEP 3 variables(col1,col34,col66)these are common in all files but the rest variables are different.I know the normal way in that we will add all the remaining variables in to MAKE sub command. that i am adding bellow

VARSTOCVASES   
/MAKE  VariableName1 FROM Col1 Col2 Col3 ....etc(except 3)
/INDEX=VariableName(VariableName1) 
/KEEP=Col1 Col34 Col66

instead of this i want to create some variable list using the (SPSSINC SELECT VARIABLES) command.I got this idea but i don't have any examples for the same.This Select query must be small which means this query should dynamically select all the variables except these 3(Col1 Col34 Col66)because i have different SPSS files and in that these 3(Col1 Col34 Col66) variables are same but the rest are different and all containing different number of variables.

IF i have a variable list(dynamically generated by excluding the 3) then i can point that in MAKE sub Command.Please any one help me.

1

1 Answers

2
votes

one way to go about this could be to rename these specific columns and then select all other variables that start with "col":

rename variables (col1 col34 col66=var1 var34 var66).
spssinc select variables MACRONAME = "!allCOL" 
   /PROPERTIES PATTERN="Col*".

Now all variables with names starting with "Col" are in the list called "!allCOL" which you can use in your syntax, for example:

VARSTOCVASES   
/MAKE VariableName1 FROM !allCOL /INDEX=VariableName(VariableName1) .

EDIT: another solution The solution above is valid only if there is a constant pattern to all the variables you want on the list. If that is not the case, this following solution enables you to name the variables that you don't want on the list, and put all the rest on the list.

* first we define a new attribute in which we mark the 
    variables we don't want on the list.

VARIABLE ATTRIBUTE VARIABLES=Car_Model_1 Car_Model_2 
     ATTRIBUTE=IncludeInMake ("no").

* now we create the list, leaving out the unwanted variables.

spssinc select variables MACRONAME = "!forMake"  
    /ATTRVALUES NAME=IncludeInMake VALUE="".  
VARSTOCVASES /MAKE Val FROM !forMake /INDEX=var(val) .