2
votes

I'm trying to write a Syntax in SPSS to look at a listed variable (FYCount) and code a new variable (FYStart) with a date that corresponds to the FYCount. Because there are 13 different FYCount variables, I've tried to do it efficiently with a DO IF ELSE IF loop, but it tells me that I haven't closed the loop. I've toggled with it for a while now and don't see why it isn't closing and executing the command. Any help for this beginner-level question would be much-appreciated!

Here's the code I have:

do if FYCount = 1.
compute FYStart = date.dmy(1,7,2003).
else if FYCount = 2.
compute FYStart = date.dmy(1,7,2004).
else if FYCount = 3.
compute FYStart = date.dmy(1,7,2005).
else if FYCount = 4.
compute FYStart = date.dmy(1,7,2006).
else if FYCount = 5.
compute FYStart = date.dmy(1,7,2007).
else if FYCount = 6.
compute FYStart = date.dmy(1,7,2008).
else if FYCount = 7.
compute FYStart = date.dmy(1,7,2009).
else if FYCount = 8.
compute FYStart = date.dmy(1,7,2010).
else if FYCount = 9.
compute FYStart = date.dmy(1,7,2011).
else if FYCount = 10.
compute FYStart = date.dmy(1,7,2012).
else if FYCount = 11.
compute FYStart = date.dmy(1,7,2013).
else if FYCount = 12.
compute FYStart = date.dmy(1,7,2014).
else if FYCount = 13.
compute FYStart = date.dmy(1,7,2015).
end if.

When I run it, I get this message: Warning # 142. Command name: EXECUTE LOOP has no effect on this command.

Error # 4095. Command name: EXECUTE The transformations program contains an unclosed LOOP, DO IF, or complex file structure. Use the level-of-control shown to the left of the SPSS Statistics commands to determine the range of LOOPs and DO IFs. Execution of this command stops

Any ideas?

2

2 Answers

1
votes

Your syntax looks good, no obvious errors.

The error message suggest you may have an EXECUTE and a DO IF or LOOP in the syntax before or after this series of DO IF statements.

Try executing all commands before this syntax to ensure the error isn't relating to something before or after. Then run this syntax alone. Close the session down and restart if necessary.

Also make sure you don't have any other nested DO IF activated. It's likely you are missing a terminating full stop somewhere...

1
votes

Assuming this is actually your code, try this:

COMPUTE FYStart = date.dmy(1,7,2002 + FYCount).