SPSS Syntax Examples
Included below are some examples of hand-coded Syntax created to efficiently complete routine data transformation in SPSS Advanced Analytics.
Creating new variable based on range calculations. |
** Count Coaches (Head, JC, AC) [new variable]
DO IF (Q0043 EQ 1). |
Re-coding value ranges into new variables. |
RECODE FlowAVG (0.0 thru 20.99=1) (21.0 thru 40.99=2) (41.0 thru 60.99=3) (61.0 thru 80.99=4) (81.0 thru 100.99=5) INTO FlowLevels. VARIABLE LABELS FlowLevels ‘Flow Levels’. EXECUTE.RECODE AGE (18 thru 30=1) (31 thru 40=2) (41 thru 50=3) (51 thru 60=4) (61 thru 98=5) INTO AgeGroup. VARIABLE LABELS AgeGroup ‘Age Group’. EXECUTE. |
Creating a global mean score by computing survey item sub-scale means then aggregating all sub-scales by summation. |
COMPUTE BalanceAVG=MEAN(q0070_0001,q0070_0010,q0071_0003,q0071_0012). EXECUTE. COMPUTE MergingAVG=MEAN(q0070_0002,q0070_0011,q0071_0004,q0071_0013). EXECUTE. COMPUTE GoalsAVG=MEAN(q0070_0003,q0070_0012,q0071_0005,q0071_0014). EXECUTE. COMPUTE FeedbackAVG=MEAN(q0070_0004,q0070_0013,q0071_0006,q0071_0015). EXECUTE. COMPUTE ConcentrationAVG=MEAN(q0070_0005,q0070_0014,q0071_0007,q0071_0016). EXECUTE. COMPUTE ControlAVG=MEAN(q0070_0006,q0070_0015,q0071_0008,q0071_0017). EXECUTE. COMPUTE ConsciousnessAVG=MEAN(q0070_0007,q0070_0016,q0071_0009,q0071_0018). EXECUTE. COMPUTE TimeAVG=MEAN(q0070_0008,q0071_0001,q0071_0010,q0071_0019). EXECUTE. COMPUTE AutotelicAVG=MEAN(q0070_0009,q0071_0002,q0071_0011,q0071_0020). EXECUTE. COMPUTE FlowAVG=SUM(BalanceAVG,MergingAVG,GoalsAVG,FeedbackAVG,ConcentrationAVG,ControlAVG,ConsciousnessAVG,TimeAVG,AutotelicAVG). EXECUTE. |
Miscellaneous scripts. |
** Computing % change from Pre to Post state COMPUTE PercChange=((ValueNow-ValueStart)/ValueStart)*100 VARIABLE LABELS PercChange ** Drop all missing cases from the current SPSS data set and save to new data file ** Create new variable based on conditions of multiple variable values. |
More to come. |