Coding query - why is it doing this?!

Soldato
Joined
22 Jan 2014
Posts
3,818
SOLVED - Coding query - why is it doing this?!

**ALWAYS check spelling for the fifth or sixth, or indeed twentieth time. I was one letter out**

Afternoon all,

I am having some difficulty in understanding why this bit of code is doing what it is in SPSS!

What I want it to do is to RECODE the variable ZopicloneCheck from '1' to '0' only if the below conditions are met. However, it is also recoding those which DO NOT qualify (e.g. Zopiclonepm=2) from ZopicloneCheck=1 to ZopicloneCheck=0 as well.

Any ideas as to why?


DO IF (Zopiclonepm=1 or Zopiclonepm=3) and (Zopicloneimp=1 or Zopicloneimp=3) and (Zopiclonepresc=1 or Zopiclonepresc=3).
RECODE ZopicloneCheck (1=0).
END IF.
EXECUTE.
 
Last edited:
Soldato
OP
Joined
22 Jan 2014
Posts
3,818
I am not familiar with the syntax of SPSS but is it because you are using assignment operators rather than comparative operators in your if statement?

i.e. in a lot of languages variable=1 assigns the value 1 whilst variable==1 compares the variable?

Thank you for your sharing your expertise RDM.
'==' is not something that SPSS seems to like having just tried to use it.

Even if that were the case, Zopicloneimp or Zopiclonepm etc. still remain at their values and are not changed by the code. It's simply the ZopicloneCheck whose value gets changed to 0 even in cases that do not qualify! It's as if it's just ignoring the DO IF qualifiers.

It's very confusing indeed.
 
Soldato
OP
Joined
22 Jan 2014
Posts
3,818
Other than by rumour, I've never actually seen SPSS before. That is one of the most disgusting languages I've ever seen.

Anyway from a quick look over the manual, is it perhaps not something like:

Code:
DO IF ((Zopiclonepm=1 OR Zopiclonepm=3) AND (Zopiclineimp=1 OR Zopiclineimp=3) AND (Zopiclonepresc=1 OR Zopiclonepresc=3)). 
RECODE ZopicloneCheck (1=0). 
END IF. 
EXECUTE.

Many thanks for this and for taking the time to look at the manual A.N.Other - though fortunately the additional brackets are not needed in this case (though I ought to have used them to be consistent as they were used by others previously). What was actually the issue was simply my noggin being screwed on the wrong way this morning.

I have Zopicline in there twice...it should have been Zopiclone every time.

Now why SPSS hasn't told me that that variable does not exist, is beyond me. Usually it throws a hissy fit with such things and just gives a nasty ERROR code!

So the issue here was me being careless and not seeing the spelling error despite (or possibly due to) staring at it for a not inconsiderable amount of time.
 
Back
Top Bottom