Adding missing data code to syntax

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

cls1
Posts: 14
Joined: Thu Nov 17, 2011 1:33 pm

Adding missing data code to syntax

Postby cls1 » Wed May 23, 2012 8:16 am

Hi,

Could anyone help me out with a coding shortcut? I've got a number of variables that I'm trying to recode into one variable, and so far have syntax that looks a bit like this: (this is just an example, it goes on to account for all the permutations - basically if any of the variables = 1 then the completev must = 1)

DATASET ACTIVATE DataSet1.
COMPUTE NEW_VAR = CompleteV.
IF (v1 = 0 AND v2 = 0 AND v3 = 0 AND v4 = 0) CompleteV = 0 .
IF (v1 = 1 AND v2 = 1 AND v3 = 1 AND v4 = 1) CompleteV = 1 .
IF (v1 = 1 AND v2 = 1 AND v3 = 1 AND v4 = 0) CompleteV = 1 .
EXECUTE .

However, this doesn't account for missing cells in the data. When I run the syntax, unsurprisingly the completev is empty if any of the cells in the other variables are missing. I'd be really grateful if someone could let me know exactly what to do to avoid this.

Thanks,

cls1
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: Adding missing data code to syntax

Postby apeape » Wed May 23, 2012 11:08 am

Here you go:

Code: Select all

comp CompleteV = 0.
if any(1, v1 to v4) CompleteV=1.
exe.
cls1
Posts: 14
Joined: Thu Nov 17, 2011 1:33 pm

Re: Adding missing data code to syntax

Postby cls1 » Wed May 23, 2012 11:14 am

Wow! That will save me so much time! Thanks so much!

Best wishes,

Cls1

Who is online

Users browsing this forum: No registered users and 1 guest

cron