Skip to main content

Data & Intelligence

Transforming Data with Loop and Vector

vectorline

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.

Data Intelligence - The Future of Big Data
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.

Get the Guide

 

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:

  1. Define the variable list using the DATA LIST command (/V1 through V20).
  2. Identify what variable response is considered to be a flag for a missing response (I’m using the value of 999).
  3. Create a new variable (“MEANSUB”) that is a calculation (the MEAN of all of the cases non-missing variable responses).
  4. Create a working ARRAY (a VECTOR) with 20 elements in it.
  5. Create the “looping logic” which will:
    1. “read through” each variable response for the current case
    2. If any variable response is missing, assign the new variable value (MEANSUB) to it
    3. Done
  6. The last steps in the script include the data (the cases) and then perform a LIST (to show the modified data)

 

myscript

Below is the modified data displayed in the SPSS “Viewer” (notice there are now no 999 values):

oput

SPSS Syntax. We could say it started as an exercise, became an addiction.”

 

Thoughts on “Transforming Data with Loop and Vector”

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Jim Miller

Mr. Miller is an IBM certified and accomplished Senior Project Leader and Application/System Architect-Developer with over 30 years of extensive applications and system design and development experience. His current role is National FPM Practice Leader. His experience includes BI, Web architecture & design, systems analysis, GUI design and testing, Database modeling and systems analysis, design, and development of Client/Server, Web and Mainframe applications and systems utilizing: Applix TM1 (including TM1 rules, TI, TM1Web and Planning Manager), dynaSight - ArcPlan, ASP, DHTML, XML, IIS, MS Visual Basic and VBA, Visual Studio, PERL, Websuite, MS SQL Server, ORACLE, SYBASE SQL Server, etc. His Responsibilities have included all aspects of Windows and SQL solution development and design including: analysis; GUI (and Web site) design; data modeling; table, screen/form and script development; SQL (and remote stored procedures and triggers) development and testing; test preparation and management and training of programming staff. Other experience includes development of ETL infrastructure such as data transfer automation between mainframe (DB2, Lawson, Great Plains, etc.) systems and client/server SQL server and Web based applications and integration of enterprise applications and data sources. In addition, Mr. Miller has acted as Internet Applications Development Manager responsible for the design, development, QA and delivery of multiple Web Sites including online trading applications, warehouse process control and scheduling systems and administrative and control applications. Mr. Miller also was responsible for the design, development and administration of a Web based financial reporting system for a 450 million dollar organization, reporting directly to the CFO and his executive team. Mr. Miller has also been responsible for managing and directing multiple resources in various management roles including project and team leader, lead developer and applications development director. Specialties Include: Cognos/TM1 Design and Development, Cognos Planning, IBM SPSS and Modeler, OLAP, Visual Basic, SQL Server, Forecasting and Planning; International Application Development, Business Intelligence, Project Development. IBM Certified Developer - Cognos TM1 (perfect score 100% on exam) IBM Certified Business Analyst - Cognos TM1

More from this Author

Follow Us