Sorry for the late answer! For some reason I wasn't notified by mail though I subscribed the theme…
Nope, unfortunately thas doesn't change anything. I am still very unsure about how many "execute."s are necessary in my code. I place them quite randomly after every major operation. Seems the first one in my example isn't necessary, though.
Penguin_Knight wrote:1) Unlike SAS, the "if" in SPSS does not require "then".
This is the original code I took from the command syntax reference:
Code: Select all
DEFINE mymacro(type = !DEFAULT(1) !TOKENS(1))
!IF (!type = 1)!then
It definitely says "!if" (not the normal if command, the one with an exclamation mark, note) requires "!then" (p. 620).
I just don't see a difference to my code:
Code: Select all
define !macro(x = !tokens(1))
!if (var1='4') !then
compute var2 = 2.
Penguin_Knight wrote:Second, the if statement can be streamlined to get rid of the compute command.
Alright. Just was an example.
Penguin_Knight wrote:You declared a macro variable "x", but you didn't refer to "x" at all in the if statement. Where should the "x" go? Replacing var1 or var2?
I know. My original code is much longer and more complex. I just eliminated every line that wasn't necessary to produce the error. I tried it with macro variables at first, and that didn't work, so I tried it without, and not even that worked! So I decided to post the easiest code I could find. And that's the one. The "!if" command definitely is the thing that's wrong wether a macro variable is used or not. And I still don't know why.
Funny though: I tried a normal "if" the next day (when I wasn't weary from long coding) myself, and it worked, just like you predicted. Thank you.
Then I tried to replace my "!do" with a "do repeat" – and that didn't work… I am still at a loss why.
So my question is: Why und where do you need these "!do" and "!if" commands? From the command syntax reference I first got the impression normal loops aren't allowed in macros. But they obviously are. So why these new commands?
And I would still be curious to know what's wrong with my original code because I don't seem to get the "!if" command working…
Thank you for your help!