As promised, today I am sharing the fundamentals of using the LOOP and VECTOR in a SPSS Syntax script.
LOOP
LOOP is a common programming concept – it simply allows you to apply or execute the same script commands for an identified number of times without having to recode them.
VECTOR
A VECTOR is (for those of us who have programming experience) how SPSS supports ARRAYS.
The Future of Big Data
With some guidance, you can craft a data platform that is right for your organization’s needs and gets the most return from your data capital.
A USEFUL EXAMPLE
In the following example we’ve taken a list of cases (case 1, 2 and 3) and their respective variable responses (V1 through V20) and applied some transformation logic to them.
The logic of the syntax script goes like this:
- Define the variable list using the DATA LIST command (/V1 through V20).
- Identify what variable response is considered to be a flag for a missing response (I’m using the value of 999).
- Create a new variable (“MEANSUB”) that is a calculation (the MEAN of all of the cases non-missing variable responses).
- Create a working ARRAY (a VECTOR) with 20 elements in it.
- Create the “looping logic” which will:
- “read through” each variable response for the current case
- If any variable response is missing, assign the new variable value (MEANSUB) to it
- Done
- The last steps in the script include the data (the cases) and then perform a LIST (to show the modified data)
Below is the modified data displayed in the SPSS “Viewer” (notice there are now no 999 values):
SPSS Syntax. We could say it started as an exercise, became an addiction.”
Hi,
I want to break single case data into stacked data without using vartocase command in SPSS.
I want to break it by using vector,loop.
Could you please provide me the syntax.
Thanks
Nirmal