12.07.2015 Views

SPSS Programming and Data Management, 4th Edition: A Guide for ...

SPSS Programming and Data Management, 4th Edition: A Guide for ...

SPSS Programming and Data Management, 4th Edition: A Guide for ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15Best Practices <strong>and</strong> Efficiency TipsIn a similar fashion, if the set of trans<strong>for</strong>mations includes a comm<strong>and</strong> that selects asubset of cases <strong>and</strong> deletes unselected cases (<strong>for</strong> example, SELECT IF), lags will becomputed after the case selection. You will probably want to avoid case selectioncriteria based on lag values—unless you EXECUTE the lags first.Using $CASENUM to Select CasesThe value of the system variable $CASENUM is dynamic. If you change the sort orderof cases, the value of $CASENUM <strong>for</strong> each case changes. If you delete the first case,the case that <strong>for</strong>merly had a value of 2 <strong>for</strong> this system variable now has the value 1.Using the value of $CASENUM with the SELECT IF comm<strong>and</strong> can be a little trickybecause SELECT IF deletes each unselected case, changing the value of $CASENUM<strong>for</strong> all remaining cases.For example, a SELECT IF comm<strong>and</strong> of the general <strong>for</strong>m:SELECT IF ($CASENUM > [positive value]).will delete all cases because regardless of the value specified, the value of $CASENUM<strong>for</strong> the current case will never be greater than 1. When the first case is evaluated, it hasa value of 1 <strong>for</strong> $CASENUM <strong>and</strong> is there<strong>for</strong>e deleted because it doesn’t have a valuegreater than the specified positive value. The erstwhile second case then becomes thefirst case, with a value of 1, <strong>and</strong> is consequently also deleted, <strong>and</strong> so on.The simple solution to this problem is to create a new variable equal to the originalvalue of $CASENUM. However, comm<strong>and</strong> syntax of the <strong>for</strong>m:COMPUTE CaseNumber=$CASENUM.SELECT IF (CaseNumber > [positive value]).will still delete all cases because each case is deleted be<strong>for</strong>e the value of the newvariable is computed. The correct solution is to insert an EXECUTE comm<strong>and</strong> betweenCOMPUTE <strong>and</strong> SELECT IF, asin:COMPUTE CaseNumber=$CASENUM.EXECUTE.SELECT IF (CaseNumber > [positive value]).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!