Simplify this syntax?

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Simplify this syntax?

Michelle Hendricks-2
Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
    DO IF (Missing(y) = 0).
          compute Diagnostic = y.
     end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Bruce Weaver
Administrator
Hello Michelle.  A little more info would be helpful.  E.g., what are the possible values of variables C01Q12.rev to C01Q23.rev?  A few rows of sample data showing what it looks like BEFORE and what you want it to look like AFTER always makes things much clearer.  ;-)

Your syntax suggests that only one of them will have a valid value on each record (with the rest missing).  If they are meant to be Yes/No indicator variables, I think it is better practice to have 1=Yes, 0=No (rather than 1=Yes, missing=No).  

One other comment:  Instead of "IF (Missing(y) = 0)", you could use "IF NOT Missing(y)".  

HTH.


Michelle Hendricks wrote
Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
    DO IF (Missing(y) = 0).
          compute Diagnostic = y.
     end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Maguin, Eugene
In reply to this post by Michelle Hendricks-2
How exactly does it not work? Give an example that fails because the syntax looks correct. Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Michelle Hendricks
Sent: Tuesday, December 10, 2013 5:07 PM
To: [hidden email]
Subject: Simplify this syntax?

Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I realize that a lot of syntax I write can be made much simpler.  The below syntax is for a survey we did in which each participant each responded to one of 12 vignettes.  They were asked the same question about each vignette, but this was coded into 12 different variables.  I simply want to combine them into one variable. The below syntax does the job, but I'm looking for a simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but I just can't get it to work correctly and I was hoping someone could tell me what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
    DO IF (Missing(y) = 0).
          compute Diagnostic = y.
     end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Rick Oliver-3
In reply to this post by Michelle Hendricks-2
Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Michelle Hendricks <[hidden email]>
To:        [hidden email],
Date:        12/10/2013 04:07 PM
Subject:        Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
   DO IF (Missing(y) = 0).
         compute Diagnostic = y.
    end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Michelle Hendricks-2

Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too. 

The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev. 

 

I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4). 

 

 

From: Rick Oliver [mailto:[hidden email]]
Sent: Tuesday, December 10, 2013 4:27 PM
To: Hendricks, Michelle A.
Cc: [hidden email]
Subject: Re: Simplify this syntax?

 

Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Michelle Hendricks <[hidden email]>
To:        [hidden email],
Date:        12/10/2013 04:07 PM
Subject:        Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>





Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
   DO IF (Missing(y) = 0).
         compute Diagnostic = y.
    end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Rick Oliver-3
In reply to this post by Bruce Weaver
Ah, yes. It took me an empirical example to realize that IF(MISSING(varname)=0) is equivalent to IF (NOT(MISSING(varname)).

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Bruce Weaver <[hidden email]>
To:        [hidden email],
Date:        12/10/2013 04:22 PM
Subject:        Re: Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello Michelle.  A little more info would be helpful.  E.g., what are the
possible values of variables C01Q12.rev to C01Q23.rev?  A few rows of sample
data showing what it looks like BEFORE and what you want it to look like
AFTER always makes things much clearer.  ;-)

Your syntax /suggests/ that only one of them will have a valid value on each
record (with the rest missing).  If they are meant to be Yes/No indicator
variables, I think it is better practice to have 1=Yes, 0=No (rather than
1=Yes, missing=No).

One other comment:  Instead of "IF (Missing(y) = 0)", you could use "IF NOT
Missing(y)".

HTH.



Michelle Hendricks wrote
> Hi,
>
> I'm new at working with SPSS syntax, and since subscribing to this list I
> realize that a lot of syntax I write can be made much simpler.  The below
> syntax is for a survey we did in which each participant each responded to
> one of 12 vignettes.  They were asked the same question about each
> vignette,
> but this was coded into 12 different variables.  I simply want to combine
> them into one variable. The below syntax does the job, but I'm looking for
> a
> simpler way.
>
> IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
> IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
> IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
> IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
> IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
> IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
> IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
> IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
> IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
> IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
> IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
> IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
> execute.
>
> I've played around with the DO REPEAT command (my attempt posted below),
> but
> I just can't get it to work correctly and I was hoping someone could tell
> me
> what I'm doing wrong!
>
>
> DO repeat y = C01Q12.rev TO C01Q23.rev .
>     DO IF (Missing(y) = 0).
>           compute Diagnostic = y.
>      end if.
> END REPEAT.
>
> Thanks,
> Michelle
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Simplify-this-syntax-tp5723556p5723557.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Michelle Hendricks-2
In reply to this post by Rick Oliver-3

In case it’s not clear what I’m trying to do, my data set looks like the below after I run those IF statements

 

       Vignette   C01Q12  C01Q13 C01Q14 Diagnostic

1              2                                              2

1              3                                              3

1              4                                              4

2                              1                              1

2                              4                              4

2                              2                              2

3                                              4              4

3                                              4              4

3                                              1              1

 

From: Hendricks, Michelle A.
Sent: Tuesday, December 10, 2013 4:33 PM
To: 'Rick Oliver'
Cc: [hidden email]
Subject: RE: Simplify this syntax?

 

Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too. 

The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev. 

 

I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4). 

 

 

From: Rick Oliver [[hidden email]]
Sent: Tuesday, December 10, 2013 4:27 PM
To: Hendricks, Michelle A.
Cc: [hidden email]
Subject: Re: Simplify this syntax?

 

Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Michelle Hendricks <[hidden email]>
To:        [hidden email],
Date:        12/10/2013 04:07 PM
Subject:        Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>





Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
   DO IF (Missing(y) = 0).
         compute Diagnostic = y.
    end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Rick Oliver-3
In reply to this post by Michelle Hendricks-2
I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.
if not(missing(y)) diagnostic=y.
end repeat.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        "Hendricks, Michelle A." <[hidden email]>
To:        Rick Oliver/Chicago/IBM@IBMUS,
Cc:        "[hidden email]" <[hidden email]>
Date:        12/10/2013 04:32 PM
Subject:        RE: Simplify this syntax?




Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.  
The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.  
 
I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).  
 
 
From: Rick Oliver [mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:27 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
Re: Simplify this syntax?

 
Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
Michelle Hendricks <michelle.hendricks@...>
To:        
[hidden email],
Date:        
12/10/2013 04:07 PM
Subject:        
Simplify this syntax?
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>





Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
  DO IF (Missing(y) = 0).
        compute Diagnostic = y.
   end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@... (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Richard Ristow
In reply to this post by Michelle Hendricks-2
At 05:07 PM 12/10/2013, Michelle Hendricks wrote:

>The syntax below is for a survey we did in which each participant
>each responded to
>one of 12 vignettes.  They were asked the same question about each
>vignette, but this was coded into 12 different variables.  I simply
>want to combine
>them into one variable.

Well, *IF* you can guarantee there's only one non-missing response,
and *IF* the twelve variables C01Q12.rev to C01Q23.rev are contiguous
in the file, then (with a hat-tip to David Marso),

COMPUTE Diagnostic=MAX(C01Q12.rev TO C01Q23.rev).

No EXECUTE statement! But to be sure you have only one non-missing
response, I advise

COMPUTE NumResponses = NVALID(C01Q12.rev TO C01Q23.rev).

Any value of NumResponses other than 1 indicates a problem in that case.

Again, no EXECUTE.

DO REPEAT is also, definitely, a useful tool:

>I've played around with the DO REPEAT command, but I just can't get
>it to work correctly:
>
>DO repeat y = C01Q12.rev TO C01Q23.rev .
>     DO IF (Missing(y) = 0).
>           compute Diagnostic = y.
>      end if.
>END REPEAT.

What goes wrong? The logic looks right to me, assuming that
C01Q12.rev TO C01Q23.rev are contiguous in your file. Is there any
chance they aren't?

Your DO REPEAT syntax can be simplified to

DO repeat y = C01Q12.rev TO C01Q23.rev .
     IF NOT MISSING(y) Diagnostic = y.
END REPEAT.

but that doesn't change the logic.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Art Kendall
In reply to this post by Michelle Hendricks-2
please post a small example of what the data looks like now and include a variable or variables that show what you want the result to be.
something like this
data list list /id co1q12.rev co1q13.rev co1q14.rev want1 want2 want3.
begin data
01 1 1 1 2 2 2
02 0 0 0 8 8 8
...
end data.

why not use
if not missing(y) diagnostic = y.
functions like "missing" return 1 if the value is missing and 0 if the value is not missing.

diagnostic will contain the last valid value of
C01Q12.rev TO C01Q23.rev

Also you naming convention seems unusual in that it does not end in sequential numbers.
Art Kendall
Social Research Consultants
On 12/10/2013 5:08 PM, Michelle Hendricks [via SPSSX Discussion] wrote:
Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
    DO IF (Missing(y) = 0).
          compute Diagnostic = y.
     end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Simplify-this-syntax-tp5723556.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Michelle Hendricks-2
In reply to this post by Rick Oliver-3

Thanks for the syntax Rick, for some reason that returns Diagnostic with all variables missing as well.  It’s similar to the syntax I wrote that also returns all empty values for Diagnostic, and I can’t quite figure out why. 

 

From: Rick Oliver [mailto:[hidden email]]
Sent: Tuesday, December 10, 2013 4:45 PM
To: Hendricks, Michelle A.
Cc: [hidden email]
Subject: RE: Simplify this syntax?

 

I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.
if not(missing(y)) diagnostic=y.
end repeat.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        "Hendricks, Michelle A." <[hidden email]>
To:        Rick Oliver/Chicago/IBM@IBMUS,
Cc:        "[hidden email]" <[hidden email]>
Date:        12/10/2013 04:32 PM
Subject:        RE: Simplify this syntax?





Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.  
The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.  
 
I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).  
 
 
From: Rick Oliver [[hidden email]]
Sent:
Tuesday, December 10, 2013 4:27 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
Re: Simplify this syntax?

 
Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
[hidden email]



From:        
Michelle Hendricks <[hidden email]>
To:        
[hidden email],
Date:        
12/10/2013 04:07 PM

Subject:        
Simplify this syntax?
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>






Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
  DO IF (Missing(y) = 0).
        compute Diagnostic = y.
   end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Rick Oliver-3
Seems to work for me.

data list list (",")  /v1 v2 v3 v4.
begin data
1,,,
,2,,
,,2,
,3,,
,,,4
end data.
do repeat x=v1 to v4.
if not(missing(x)) newvar=x.
end repeat.
list.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        "Hendricks, Michelle A." <[hidden email]>
To:        Rick Oliver/Chicago/IBM@IBMUS,
Cc:        "[hidden email]" <[hidden email]>
Date:        12/10/2013 04:51 PM
Subject:        RE: Simplify this syntax?




Thanks for the syntax Rick, for some reason that returns Diagnostic with all variables missing as well.  It’s similar to the syntax I wrote that also returns all empty values for Diagnostic, and I can’t quite figure out why.  
 
From: Rick Oliver [mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:45 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
RE: Simplify this syntax?

 
I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.

if not(missing(y)) diagnostic=y.

end repeat.




Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
"Hendricks, Michelle A." <michelle.hendricks@...>
To:        
Rick Oliver/Chicago/IBM@IBMUS,
Cc:        
"[hidden email]" <[hidden email]>
Date:        
12/10/2013 04:32 PM
Subject:        
RE: Simplify this syntax?





Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.  

The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.  

 
I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).  

 
 
From:
Rick Oliver [
mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:27 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
Re: Simplify this syntax?

 

Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
Michelle Hendricks <michelle.hendricks@...>
To:        
[hidden email],
Date:        
12/10/2013 04:07 PM
Subject:        
Simplify this syntax?
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>






Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
 DO IF (Missing(y) = 0).
       compute Diagnostic = y.
  end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@... (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Michelle Hendricks-2

You’re right, I did get it to work, thank you!

 

From: Rick Oliver [mailto:[hidden email]]
Sent: Tuesday, December 10, 2013 4:58 PM
To: Hendricks, Michelle A.
Cc: [hidden email]
Subject: RE: Simplify this syntax?

 

Seems to work for me.

data list list (",")  /v1 v2 v3 v4.
begin data
1,,,
,2,,
,,2,
,3,,
,,,4
end data.
do repeat x=v1 to v4.
if not(missing(x)) newvar=x.
end repeat.
list.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        "Hendricks, Michelle A." <[hidden email]>
To:        Rick Oliver/Chicago/IBM@IBMUS,
Cc:        "[hidden email]" <[hidden email]>
Date:        12/10/2013 04:51 PM
Subject:        RE: Simplify this syntax?





Thanks for the syntax Rick, for some reason that returns Diagnostic with all variables missing as well.  It’s similar to the syntax I wrote that also returns all empty values for Diagnostic, and I can’t quite figure out why.  
 
From: Rick Oliver [[hidden email]]
Sent:
Tuesday, December 10, 2013 4:45 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
RE: Simplify this syntax?

 
I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.

if not(missing(y)) diagnostic=y.

end repeat.




Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
[hidden email]



From:        
"Hendricks, Michelle A." <[hidden email]>
To:        
Rick Oliver/Chicago/IBM@IBMUS,
Cc:        
"
[hidden email]" <[hidden email]>
Date:        
12/10/2013 04:32 PM
Subject:        
RE: Simplify this syntax?






Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.  

The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.  

 
I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).  

 
 
From:
Rick Oliver [[hidden email]]
Sent:
Tuesday, December 10, 2013 4:27 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
Re: Simplify this syntax?
 
Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
[hidden email]



From:        
Michelle Hendricks <[hidden email]>
To:        
[hidden email],
Date:        
12/10/2013 04:07 PM

Subject:        
Simplify this syntax?
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>







Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
 DO IF (Missing(y) = 0).
       compute Diagnostic = y.
  end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to

[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Rick Oliver-3
In reply to this post by Michelle Hendricks-2
But the end result is only useful if you don't care which original variable the value came from.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        Rick Oliver/Chicago/IBM
To:        "Hendricks, Michelle A." <[hidden email]>,
Cc:        "[hidden email]" <[hidden email]>
Date:        12/10/2013 04:57 PM
Subject:        RE: Simplify this syntax?



Seems to work for me.

data list list (",")  /v1 v2 v3 v4.
begin data
1,,,
,2,,
,,2,
,3,,
,,,4
end data.
do repeat x=v1 to v4.
if not(missing(x)) newvar=x.
end repeat.
list.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]





From:        "Hendricks, Michelle A." <[hidden email]>
To:        Rick Oliver/Chicago/IBM@IBMUS,
Cc:        "[hidden email]" <[hidden email]>
Date:        12/10/2013 04:51 PM
Subject:        RE: Simplify this syntax?




Thanks for the syntax Rick, for some reason that returns Diagnostic with all variables missing as well.  It’s similar to the syntax I wrote that also returns all empty values for Diagnostic, and I can’t quite figure out why.  
 
From: Rick Oliver [mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:45 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
RE: Simplify this syntax?

 
I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.

if not(missing(y)) diagnostic=y.

end repeat.




Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
"Hendricks, Michelle A." <michelle.hendricks@...>
To:        
Rick Oliver/Chicago/IBM@IBMUS,
Cc:        
"[hidden email]" <[hidden email]>
Date:        
12/10/2013 04:32 PM
Subject:        
RE: Simplify this syntax?





Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.  

The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.  

 
I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).  

 
 
From:
Rick Oliver [
mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:27 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
Re: Simplify this syntax?

 

Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
Michelle Hendricks <michelle.hendricks@...>
To:        
[hidden email],
Date:        
12/10/2013 04:07 PM
Subject:        
Simplify this syntax?
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>






Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
 DO IF (Missing(y) = 0).
       compute Diagnostic = y.
  end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@... (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Rick Oliver-3
In reply to this post by Michelle Hendricks-2
If only one variable has a valid value, then

compute newvar=sum(varlist)

will work just fine.

data list list (",")  /v1 v2 v3 v4.
begin data
1,,,
,2,,
,,2,
,3,,
,,,4
end data.
do repeat x=v1 to v4.
if not(missing(x)) newvar=x.
end repeat.
compute simpler=sum(v1, v2, v3, v4).
list.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]




From:        "Hendricks, Michelle A." <[hidden email]>
To:        [hidden email],
Date:        12/10/2013 05:04 PM
Subject:        Re: Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




You’re right, I did get it to work, thank you!
 
From: Rick Oliver [mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:58 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
RE: Simplify this syntax?

 
Seems to work for me.

data list list (",")  /v1 v2 v3 v4.

begin data

1,,,

,2,,

,,2,

,3,,

,,,4

end data.

do repeat x=v1 to v4.

if not(missing(x)) newvar=x.

end repeat.

list.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
"Hendricks, Michelle A." <michelle.hendricks@...>
To:        
Rick Oliver/Chicago/IBM@IBMUS,
Cc:        
"[hidden email]" <[hidden email]>
Date:        
12/10/2013 04:51 PM
Subject:        
RE: Simplify this syntax?





Thanks for the syntax Rick, for some reason that returns Diagnostic with all variables missing as well.  It’s similar to the syntax I wrote that also returns all empty values for Diagnostic, and I can’t quite figure out why.  

 
From:
Rick Oliver [
mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:45 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
RE: Simplify this syntax?

 

I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:


DO repeat y = C01Q12.rev TO C01Q23.rev.

if not(missing(y)) diagnostic=y.

end repeat.




Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
"Hendricks, Michelle A." <michelle.hendricks@...>
To:        
Rick Oliver/Chicago/IBM@IBMUS,
Cc:        
"[hidden email]" <[hidden email]>
Date:        
12/10/2013 04:32 PM
Subject:        
RE: Simplify this syntax?






Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.  

The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.  


I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).  



From:
Rick Oliver [
mailto:oliverr@...]
Sent:
Tuesday, December 10, 2013 4:27 PM
To:
Hendricks, Michelle A.
Cc:
[hidden email]
Subject:
Re: Simplify this syntax?


Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail:
oliverr@...



From:        
Michelle Hendricks <michelle.hendricks@...>
To:        
[hidden email],
Date:        
12/10/2013 04:07 PM
Subject:        
Simplify this syntax?
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>







Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
DO IF (Missing(y) = 0).
      compute Diagnostic = y.
 end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@... (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Bruce Weaver
Administrator
In reply to this post by Michelle Hendricks-2
Do you see "Transformations pending" in the lower right corner of the data editor?  Does it work if you add a frequencies command, like this?

DO repeat y = C01Q12.rev TO C01Q23.rev.
if not(missing(y)) diagnostic=y.
end repeat.
FREQEUENCIES diagnostic.



Michelle Hendricks wrote
Thanks for the syntax Rick, for some reason that returns Diagnostic with all variables missing as well.  It’s similar to the syntax I wrote that also returns all empty values for Diagnostic, and I can’t quite figure out why.

From: Rick Oliver [mailto:[hidden email]]
Sent: Tuesday, December 10, 2013 4:45 PM
To: Hendricks, Michelle A.
Cc: [hidden email]
Subject: RE: Simplify this syntax?

I must still be missing something. I think all this code will do is set diagnostic to the last variable specified that has a non-missing value. Is that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.
if not(missing(y)) diagnostic=y.
end repeat.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]<mailto:[hidden email]>



From:        "Hendricks, Michelle A." <[hidden email]<mailto:[hidden email]>>
To:        Rick Oliver/Chicago/IBM@IBMUS,
Cc:        "[hidden email]<mailto:[hidden email]>" <[hidden email]<mailto:[hidden email]>>
Date:        12/10/2013 04:32 PM
Subject:        RE: Simplify this syntax?
________________________________



Yep, the separate IF statements do work, I’ve just done it on my data set, and I’ve used this syntax before too.
The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if it’s not missing, then it sets the new variable (Diagnostic) to the value of C01Q12.rev.

I have values of 1 through 4 for each of the variables, and it is returning what it should into the new variable (i.e., if C01Q12 is not missing and equals 4, then Diagnostic = 4).


From: Rick Oliver [mailto:[hidden email]]
Sent: Tuesday, December 10, 2013 4:27 PM
To: Hendricks, Michelle A.
Cc: [hidden email]<mailto:[hidden email]>
Subject: Re: Simplify this syntax?

Do the separate IF statements work? I can't figure out what condition Missing(varname)=0 is checking for. Assuming this this works at all, it will only set Diagnostic to the value of the other variable when the value of the other variable is 0, so the only valid value you will ever have for Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]<mailto:[hidden email]>



From:        Michelle Hendricks <[hidden email]<mailto:[hidden email]>>
To:        [hidden email]<mailto:[hidden email]>,
Date:        12/10/2013 04:07 PM
Subject:        Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]<mailto:[hidden email]>>
________________________________




Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below), but
I just can't get it to work correctly and I was hoping someone could tell me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
  DO IF (Missing(y) = 0).
        compute Diagnostic = y.
   end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email]<mailto:[hidden email]> (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

David Marso
Administrator
In reply to this post by Rick Oliver-3
" I think all this code will do is set diagnostic to the last variable specified that has a non-missing value."
I don't think it will.  I KNOW IT WILL!
OP needs to create correct syntax before attempting to simplify defective syntax!

Rick Oliver wrote
I must still be missing something. I think all this code will do is set
diagnostic to the last variable specified that has a non-missing value. Is
that what you want? If so, then:

DO repeat y = C01Q12.rev TO C01Q23.rev.
if not(missing(y)) diagnostic=y.
end repeat.



Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]



From:   "Hendricks, Michelle A." <[hidden email]>
To:     Rick Oliver/Chicago/IBM@IBMUS,
Cc:     "[hidden email]" <[hidden email]>
Date:   12/10/2013 04:32 PM
Subject:        RE: Simplify this syntax?



Yep, the separate IF statements do work, I’ve just done it on my data set,
and I’ve used this syntax before too.
The (Missing(C01Q12) = 0) bit just checks if C01Q12 is NOT missing, and if
it’s not missing, then it sets the new variable (Diagnostic) to the value
of C01Q12.rev.
 
I have values of 1 through 4 for each of the variables, and it is
returning what it should into the new variable (i.e., if C01Q12 is not
missing and equals 4, then Diagnostic = 4).
 
 
From: Rick Oliver [mailto:[hidden email]]
Sent: Tuesday, December 10, 2013 4:27 PM
To: Hendricks, Michelle A.
Cc: [hidden email]
Subject: Re: Simplify this syntax?
 
Do the separate IF statements work? I can't figure out what condition
Missing(varname)=0 is checking for. Assuming this this works at all, it
will only set Diagnostic to the value of the other variable when the value
of the other variable is 0, so the only valid value you will ever have for
Diagnostic is 0.

Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email] 



From:        Michelle Hendricks <[hidden email]>
To:        [hidden email],
Date:        12/10/2013 04:07 PM
Subject:        Simplify this syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi,

I'm new at working with SPSS syntax, and since subscribing to this list I
realize that a lot of syntax I write can be made much simpler.  The below
syntax is for a survey we did in which each participant each responded to
one of 12 vignettes.  They were asked the same question about each
vignette,
but this was coded into 12 different variables.  I simply want to combine
them into one variable. The below syntax does the job, but I'm looking for
a
simpler way.

IF (Missing(C01Q12.rev) = 0) Diagnostic = C01Q12.rev.
IF (Missing(C01Q13.rev) = 0) Diagnostic = C01Q13.rev.
IF (Missing(C01Q14.rev) = 0) Diagnostic = C01Q14.rev.
IF (Missing(C01Q15.rev) = 0) Diagnostic = C01Q15.rev.
IF (Missing(C01Q16.rev) = 0) Diagnostic = C01Q16.rev.
IF (Missing(C01Q17.rev) = 0) Diagnostic = C01Q17.rev.
IF (Missing(C01Q18.rev) = 0) Diagnostic = C01Q18.rev.
IF (Missing(C01Q19.rev) = 0) Diagnostic = C01Q19.rev.
IF (Missing(C01Q20.rev) = 0) Diagnostic = C01Q20.rev.
IF (Missing(C01Q21.rev) = 0) Diagnostic = C01Q21.rev.
IF (Missing(C01Q22.rev) = 0) Diagnostic = C01Q22.rev.
IF (Missing(C01Q23.rev) = 0) Diagnostic = C01Q23.rev.
execute.

I've played around with the DO REPEAT command (my attempt posted below),
but
I just can't get it to work correctly and I was hoping someone could tell
me
what I'm doing wrong!


DO repeat y = C01Q12.rev TO C01Q23.rev .
   DO IF (Missing(y) = 0).
         compute Diagnostic = y.
    end if.
END REPEAT.

Thanks,
Michelle

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Richard Ristow
At 06:50 PM 12/10/2013, David Marso wrote:
>" I think all this code will do is set diagnostic to the last variable
>specified that has a non-missing value."
>don't think it will.  I KNOW IT WILL!
>OP needs to create correct syntax before attempting to simplify defective
>syntax!

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

Richard Ristow
In reply to this post by David Marso
At 06:50 PM 12/10/2013, David Marso wrote:
>>I think all this code will do is set diagnostic to the last
>>variable specified that has a non-missing value.
>
>I don't think it will.  I KNOW IT WILL!
>OP needs to create correct syntax before attempting to simplify
>defective syntax!

But it may not be defective. In the original posting, at 05:07 PM
12/10/2013, Michelle Hendricks asked:

>We did [a survey] in which each participant each responded to one of
>12 vignettes.  [Each was] asked the same question about [their]
>vignette, but [the answers were] coded into 12 different
>variables.  I simply want to combine them into one variable.

As I understand this, there should be exactly one non-missing value
among those twelve (C01Q12.rev TO C01Q23.rev); as long as that's
true, setting 'Diagnostic' to the first, or last, non-missing value
will pick up that single non-missing value.

As I noted above, it's well to put in a test to assure that there
*is* exactly one, or at most one, non-missing value.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Simplify this syntax?

David Marso
Administrator

OK.  I see.
Wonder why anyone would enter data that way rather than 2 vars vignette_number score?

Richard Ristow wrote
At 06:50 PM 12/10/2013, David Marso wrote:
>>I think all this code will do is set diagnostic to the last
>>variable specified that has a non-missing value.
>
>I don't think it will.  I KNOW IT WILL!
>OP needs to create correct syntax before attempting to simplify
>defective syntax!

But it may not be defective. In the original posting, at 05:07 PM
12/10/2013, Michelle Hendricks asked:

>We did [a survey] in which each participant each responded to one of
>12 vignettes.  [Each was] asked the same question about [their]
>vignette, but [the answers were] coded into 12 different
>variables.  I simply want to combine them into one variable.

As I understand this, there should be exactly one non-missing value
among those twelve (C01Q12.rev TO C01Q23.rev); as long as that's
true, setting 'Diagnostic' to the first, or last, non-missing value
will pick up that single non-missing value.

As I noted above, it's well to put in a test to assure that there
*is* exactly one, or at most one, non-missing value.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
12