* ======================================================================= * File: restructure_the_old_fashioned_way.SPS . * Date: 8-Apr-2004 . * Author: Bruce Weaver, weaverb@mcmaster.ca . * Notes: CASESTOVARS and VARSTOCASES before the Restructure Wizard . * ======================================================================= . * This file demonstrates how to do achieve the same results as CasesToVars * and VarsToCases the old fashioned way (prior to version 11, when the * Restructure Wizard was introduced). * Restructure from LONG file to WIDE (i.e., CasesToVars) . DATA LIST LIST /ssn (f2.0) diagnum (f2.0) score (f5.0) . BEGIN DATA. 1 1 25 1 2 34 1 4 29 1 5 18 2 1 40 2 2 38 2 3 19 2 4 24 2 5 28 END DATA. var lab ssn 'Social security number' diagnum 'Diagnostic number' score 'Diagnostic score'. list. numeric score1 to score5 (f5.0). exe. vector sc = score1 to score5. loop #i = 1 to 5. if (diagnum = #i) sc(#i) = score. end loop. exe. aggregate outfile = * /presorted /break = ssn /score1 = first(score1) /score2 = first(score2) /score3 = first(score3) /score4 = first(score4) /score5 = first(score5). list. * Now restructure from WIDE to LONG, or VarsToCases . numeric diagnum score (f5.0). vector s = score1 to score5. loop #i = 1 to 5. - compute diagnum = #i. - compute score = s(#i). - xsave outfile = "c:\temp\temp.sav" /keep = ssn diagnum score. end loop. exe. get file = "c:\temp\temp.sav" . list. * End of job. * ======================================================================= .