2
votes

I am trying to restructure one .sav file using VARSTOCASES command and i got one syntax from IBM site,but i didn't get any examples for the same so i tried with some variables but its not working,Can anyone help for this

Actual Syntax from IBM Site

VARSTOCASES

/MAKE new variable ["label"] [FROM] varlist [/MAKE ...]

[/INDEX = {new variable ["label"]                                  }]
      {new variable ["label"] (make variable name)             }
      {new variable ["label"] (n) new variable ["label"](n) ...}

[/ID = new variable ["label"]]

[/NULL = {DROP**}]
     {KEEP  }

[/COUNT=new variable ["label"]]

[/KEEP={ALL**  }] [/DROP=varlist] 
   {varlist}

My code

GET
FILE='D:\SPSStoCSV\FileFormator\bin\FILES\Argentina\Temp.sav'.
DATASET NAME DataSet1 WINDOW=FRONT.

VARSTOCASES
/MAKE new variable VariableName1 [FROM] varlist [/MAKE  Purchp6m_2 Purchp6m_4]

[/INDEX = {new variable VariableName1                                  }]
      {new variable VariableName1 (make variable name)             }
      {new variable VariableName1 (3) new variable VariableName1(3) ...}

[/ID = new variable VariableName1]
[/NULL = {DROP**}]
         {KEEP  }
[/COUNT=new variable VariableName1]

[/KEEP={ALL**  }] [/DROP=varlist] 
     {varlist}.

SAVE TRANSLATE OUTFILE='C:\Users\10522\Desktop\Temp.csv'
/TYPE=CSV
/ENCODING='UTF8'
/MAP
/REPLACE
/FIELDNAMES
/CELLS=VALUES.

here i want to keep all the variables except these 2(Purchp6m_2 Purchp6m_4)in KEEP command,Here i have some 150 variables so instead of keeping all the 148 variable names in the KEEP command i am trying like All** and DROP command, but this is giving all data without restructuring any of the variables.I am trying to avoid adding all the remaining variables in the KEEP command.

1

1 Answers

2
votes

First, remove the square and the curly brackets [, ], { and }. They are used on IBM website only to signal optional arguments and lists of variables; they are not part of the syntax itself.

Second, you cannot use spaces in your variable names, so new variableshould be new_variable

Third, you are using new_variable multiple times, which is wrong. you need to assign actual names to those variables.

Your code needs to be something like this: (although it is not very clear neither to me, and probably nor to you, why you need all the optional arguments):

GET
FILE='D:\SPSStoCSV\FileFormator\bin\FILES\Argentina\Temp.sav'.
DATASET NAME DataSet1 WINDOW=FRONT.

VARSTOCASES
/MAKE Purchp6m "Purchp6m" FROM Purchp6m_2 Purchp6m_4
/INDEX = index_variable "Index variable"
/ID = id_variable "Variable ID"
/NULL = KEEP
/COUNT=count_variable "Count VAriable"
/KEEP=ALL.
EXECUTE.

SAVE TRANSLATE OUTFILE='C:\Users\10522\Desktop\Temp.csv'
/TYPE=CSV
/ENCODING='UTF8'
/MAP
/REPLACE
/FIELDNAMES
/CELLS=VALUES.

KEEP=ALL is the default, so you don't actually need to specify it