PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 9, 2022

[FIXED] How can you run a loop in SPSS syntax that calculates the difference between many sets of variables?

 December 09, 2022     loops, spss, syntax     No comments   

Issue

I have a set of variables (A1, A2, B1, B2, C1, C3 ...) that I need to calculate the difference for to eventually create a set of Bland-Altman plots after extracting the mean difference and sd of the difference from a t-test using OMS.

As a first step I have it working for a single pair of variables (e.g. A1 and A2) and am now trying to create a macro that will loop through the first few pairs as a test:

```
DEFINE BlandAlt (scan1vars=!CMDEND / scan2vars=!CMDEND) 
COMPUTE diff = scan1vars - scan2vars.
EXECUTE.

T-TEST
/TESTVAL=0
/MISSING=ANALYSIS
/VARIABLES=diff
/CRITERIA=CI(.95).

 !ENDDEFINE.

BlandAlt 
scan1vars = JumpJumpHeightcm.1 JumpJumpHeightt_score.1 JumpMaxChangeinAccelerationms3.1 JumpMaxChangeinAccelerationt_score.1 JumpMaxAccelerationms2.1 JumpMaxAccelerationt_score.1 
scan2vars= JumpJumpHeightcm.2 JumpJumpHeightt_score.2  JumpMaxChangeinAccelerationms3.2  JumpMaxChangeinAccelerationt_score.2  JumpMaxAccelerationms2.2 JumpMaxAccelerationt_score.2.
```

When I run the macro I get an error on the first variable:

Error # 4381 in column 35. Text: JumpJumpHeightt_score.1 The expression ends unexpectedly. Execution of this command stops.

and a warning when it tries to run the t-test:

Text: diff Command: T-TEST An undefined variable name, or a scratch or system variable was specified in a variable list >which accepts only standard variables. Check spelling and verify the existence of this variable. Execution of this command stops.

Is anyone able to help get this part working? I'm hoping it should then be easy to include the other commands within the macro.


Solution

See my comment for corrections to your original macro. After correcting the macru it should work well, only you are not using the macro call the way it is built. You need to call it this way:

BlandAlt scan1vars = JumpJumpHeightcm.1 / scan2vars= JumpJumpHeightcm.2 .
BlandAlt scan1vars = JumpJumpHeightt_score.1 / scan2vars=JumpJumpHeightt_score.2 .
...

Now this is obviously not looping throug your variable list. The problem with SPSS macro is that it's very difficult to get it to loop through two lists at the same time. But in your case, there is no need - there is only one actual list to loop through, while letting the macro add the 1 or 2 suffix to the variable name. Try this:

DEFINE BlandAlt (vrs=!CMDEND) 
!do !vr !in(!vrs)
COMPUTE diff = !concat(!vr,".1") - !concat(!vr,".2").
EXECUTE.
TTEST.....
!doend
!enddefine.

Now the macro call would look like this:

BlandAlt vrs = JumpJumpHeightcm JumpJumpHeightt_score JumpMaxChangeinAccelerationms3  
  JumpMaxChangeinAccelerationt_score JumpMaxAccelerationms2 JumpMaxAccelerationt_score .


Answered By - eli-k
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing