Syntax commands to run only 1 of 2 alternative analyses

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

fruitbelt
Posts: 1
Joined: Mon May 14, 2012 3:25 pm

Syntax commands to run only 1 of 2 alternative analyses

Postby fruitbelt » Tue May 15, 2012 1:17 pm

Is there a way to use something like an "if" command to only run 1 of 2 alternative analyses.

if loops only do transformation statements, not analysis statements.

For example:

if Code=1 do this:
fre Variable1
if Code =2 do this:
des Variable1
Penguin_Knight
Posts: 473
Joined: Thu Apr 05, 2012 5:58 pm

Re: Syntax commands to run only 1 of 2 alternative analyses

Postby Penguin_Knight » Tue May 15, 2012 1:39 pm

You can check "IF" and "ELSE". Examples here:
http://www.psy.mq.edu.au/psystat/docume ... aManip.PDF

Just also want to point out that your example is a bit weird. If you have 50 1's and 50 2's in the variable Code, you'll just end up with 50 frequency tables and 50 descriptive of the same variable Variable1.
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: Syntax commands to run only 1 of 2 alternative analyses

Postby apeape » Tue May 15, 2012 3:23 pm

No, conditionals can't be applied to analyses such as frequencies and descriptives. It doesn't make any sense. From the information you've given I can't understand what you're trying to achieve. If you're trying to apply an analysis to only a subset of your data, look into the 'select if' command.
JonPedersen
Posts: 117
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Syntax commands to run only 1 of 2 alternative analyses

Postby JonPedersen » Wed May 16, 2012 5:55 am

Hi,
This depends a bit on what you want to do.
It is quite possible in SPSS to run one of two alternative analyses, either using the macro facility or Python programmability.
The macro version is here

Code: Select all

Define onetwo (CODE=!TOKENS(1))
!IF (!CODE !EQ 1) !THEN
  Freq V1.
!ELSE
  Freq V2.
!IFEND
!ENDDEFINE.

onetwo CODE=1.
onetwo CODE=2.

You can put as many spss commands as you like where Freq V1 and Freq V2 is located.
Note that the CODE gets its value from you as part of the syntax - the code value is not data driven. If you want to have it data driven (say, as a consequence of some earlier analysis) it is simpler to do it with Python.
hth
Jon

Who is online

Users browsing this forum: No registered users and 2 guests

cron