IF sentence

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

IF sentence

Elina Tenhunen
Hi, can anyone tell me what is wrong with this

IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
ELSE IF mt = 0.
EXECUTE.

And how to fix it.

-Elina from Finland

=====================
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: IF sentence

Spousta Jan
Hi Elina,

It should be probably something like this (untested) code:

DO IF not missing(Pvm.11).
- COMPUTE mt = (Pvm.11 - Pvm.1).
ELSE IF not missing(Pvm.10).
- COMPUTE mt = (Pvm.10 - Pvm.1).

etc. etc.

ELSE .
- COMPUTE mt = 0.
EXECUTE.

But a more SPSS-like approach would be:

COMPUTE mt = 0.
DO REPEAT var = Pvm.2 TO Pvm.11.
- IF not missing(var) mt = var - Pvm.1 .
END REPEAT.
EXE.

Yes, use loops whenever possible.

Best,

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Elina Tenhunen
Sent: Tuesday, May 11, 2010 3:09 PM
To: [hidden email]
Subject: IF sentence

Hi, can anyone tell me what is wrong with this

IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
ELSE IF mt = 0.
EXECUTE.

And how to fix it.

-Elina from Finland

=====================
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



_____________
Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --

=====================
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: IF sentence

Maguin, Eugene
In reply to this post by Elina Tenhunen
Elina,

It almost looks like you are writing sas syntax and not spss syntax. So, I
guessing that 'if pvm.11 =.' means do what follows if pvm.ll is missing. You
need to do some reading in the syntax reference for the following commands
and keywords: Do if-End if, Sysmis (as a function), If, and Compute.

In spss the following would be

DO IF (sysmis(Pvm.11)).
+  COMPUTE mt = (Pvm.11 - Pvm.1).
ELSE IF (SYSMIS(Pvm.10)).
+  COMPUTE mt = (Pvm.10 - Pvm.1).
ELSE IF (SYSMIS(Pvm.9)).
+  COMPUTE mt = (Pvm.9 - Pvm.1).
ELSE IF (SYSMIS(Pvm.8)).
+  COMPUTE mt = (Pvm.8- Pvm.1).
ELSE IF (SYSMIS(Pvm.7)).
+  COMPUTE mt = (Pvm.7 - Pvm.1).
ELSE IF (SYSMIS(Pvm.6)).
+  COMPUTE mt = (Pvm.6 - Pvm.1).
ELSE IF (SYSMIS(Pvm.5)).
+  COMPUTE mt = (Pvm.5 - Pvm.1).
ELSE IF (SYSMIS(Pvm.4)).
+  COMPUTE mt = (Pvm.4 - Pvm.1).
ELSE IF (SYSMIS(Pvm.3)).
+  COMPUTE mt = (Pvm.3 - Pvm.1).
ELSE IF (SYSMIS(Pvm.2)).
+  COMPUTE mt = (Pvm.2 - Pvm.1).
ELSE.
+  COMPUTE mt = 0.
END IF.
EXECUTE.


Now, if you do some more reading and read about the Do repeat-End repeat
command structure you can simplify things greatly.

DO REPEAT X=Pvm.2 Pvm.3 Pvm.4 Pvm.5 Pvm.6 Pvm.7 Pvm.8 Pvm.9 Pvm.10 Pvm.11.
+  COMPUTE mt = 0.
+  IF (sysmis(X)) mt = (X - Pvm.1).
END REPEAT.
EXECUTE.

Gene Maguin


>>Hi, can anyone tell me what is wrong with this

IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
ELSE IF mt = 0.
EXECUTE.

And how to fix it.

-Elina from Finland

=====================
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: IF sentence

Spousta Jan
I am very sorry Gene, but your code probably does not work as Elina thinks. If a variable is missing, you cannot compute a difference with it. :-) Therefore I guess that Elina wishes to test whether the variables are _not_ missing.

Best regards,

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Tuesday, May 11, 2010 3:37 PM
To: [hidden email]
Subject: Re: IF sentence

Elina,

It almost looks like you are writing sas syntax and not spss syntax. So, I guessing that 'if pvm.11 =.' means do what follows if pvm.ll is missing. You need to do some reading in the syntax reference for the following commands and keywords: Do if-End if, Sysmis (as a function), If, and Compute.

In spss the following would be

DO IF (sysmis(Pvm.11)).
+  COMPUTE mt = (Pvm.11 - Pvm.1).
ELSE IF (SYSMIS(Pvm.10)).
+  COMPUTE mt = (Pvm.10 - Pvm.1).
ELSE IF (SYSMIS(Pvm.9)).
+  COMPUTE mt = (Pvm.9 - Pvm.1).
ELSE IF (SYSMIS(Pvm.8)).
+  COMPUTE mt = (Pvm.8- Pvm.1).
ELSE IF (SYSMIS(Pvm.7)).
+  COMPUTE mt = (Pvm.7 - Pvm.1).
ELSE IF (SYSMIS(Pvm.6)).
+  COMPUTE mt = (Pvm.6 - Pvm.1).
ELSE IF (SYSMIS(Pvm.5)).
+  COMPUTE mt = (Pvm.5 - Pvm.1).
ELSE IF (SYSMIS(Pvm.4)).
+  COMPUTE mt = (Pvm.4 - Pvm.1).
ELSE IF (SYSMIS(Pvm.3)).
+  COMPUTE mt = (Pvm.3 - Pvm.1).
ELSE IF (SYSMIS(Pvm.2)).
+  COMPUTE mt = (Pvm.2 - Pvm.1).
ELSE.
+  COMPUTE mt = 0.
END IF.
EXECUTE.


Now, if you do some more reading and read about the Do repeat-End repeat command structure you can simplify things greatly.

DO REPEAT X=Pvm.2 Pvm.3 Pvm.4 Pvm.5 Pvm.6 Pvm.7 Pvm.8 Pvm.9 Pvm.10 Pvm.11.
+  COMPUTE mt = 0.
+  IF (sysmis(X)) mt = (X - Pvm.1).
END REPEAT.
EXECUTE.

Gene Maguin


>>Hi, can anyone tell me what is wrong with this

IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
ELSE IF mt = 0.
EXECUTE.

And how to fix it.

-Elina from Finland

=====================
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



_____________
Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --

=====================
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: IF sentence

Maguin, Eugene
Hi Jan,

Yes, I understand what you are saying about what I posted. My code doesn't
make sense. Did I misunderstand the meaning of the '.' in the original
statement? If so, then it seems like there is a logic error in Elina's
original code.

Gene Maguin



I am very sorry Gene, but your code probably does not work as Elina thinks.
If a variable is missing, you cannot compute a difference with it. :-)
Therefore I guess that Elina wishes to test whether the variables are _not_
missing.

Best regards,

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Gene Maguin
Sent: Tuesday, May 11, 2010 3:37 PM
To: [hidden email]
Subject: Re: IF sentence

Elina,

It almost looks like you are writing sas syntax and not spss syntax. So, I
guessing that 'if pvm.11 =.' means do what follows if pvm.ll is missing. You
need to do some reading in the syntax reference for the following commands
and keywords: Do if-End if, Sysmis (as a function), If, and Compute.

In spss the following would be

DO IF (sysmis(Pvm.11)).
+  COMPUTE mt = (Pvm.11 - Pvm.1).
ELSE IF (SYSMIS(Pvm.10)).
+  COMPUTE mt = (Pvm.10 - Pvm.1).
ELSE IF (SYSMIS(Pvm.9)).
+  COMPUTE mt = (Pvm.9 - Pvm.1).
ELSE IF (SYSMIS(Pvm.8)).
+  COMPUTE mt = (Pvm.8- Pvm.1).
ELSE IF (SYSMIS(Pvm.7)).
+  COMPUTE mt = (Pvm.7 - Pvm.1).
ELSE IF (SYSMIS(Pvm.6)).
+  COMPUTE mt = (Pvm.6 - Pvm.1).
ELSE IF (SYSMIS(Pvm.5)).
+  COMPUTE mt = (Pvm.5 - Pvm.1).
ELSE IF (SYSMIS(Pvm.4)).
+  COMPUTE mt = (Pvm.4 - Pvm.1).
ELSE IF (SYSMIS(Pvm.3)).
+  COMPUTE mt = (Pvm.3 - Pvm.1).
ELSE IF (SYSMIS(Pvm.2)).
+  COMPUTE mt = (Pvm.2 - Pvm.1).
ELSE.
+  COMPUTE mt = 0.
END IF.
EXECUTE.


Now, if you do some more reading and read about the Do repeat-End repeat
command structure you can simplify things greatly.

DO REPEAT X=Pvm.2 Pvm.3 Pvm.4 Pvm.5 Pvm.6 Pvm.7 Pvm.8 Pvm.9 Pvm.10 Pvm.11.
+  COMPUTE mt = 0.
+  IF (sysmis(X)) mt = (X - Pvm.1).
END REPEAT.
EXECUTE.

Gene Maguin


>>Hi, can anyone tell me what is wrong with this

IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
ELSE IF mt = 0.
EXECUTE.

And how to fix it.

-Elina from Finland

=====================
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



_____________
Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně
adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv
zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže
jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte
zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo
opomenutí způsobené tímto přenosem.

Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její
přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for
the addressee(s). Any publication, transmission or other use of the
information by a person or entity other than the intended addressee is
prohibited. If you receive this in error please contact the sender and
delete the message as well as all attached documents. The sender does not
accept liability for any errors or omissions as a result of the
transmission.

Are you sure that you really need a print version of this message and/or its
attachments? Think about nature.

-.- --

=====================
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: IF sentence

Spousta Jan
Hi Gene,

I understand it in the way that Elina wished to test the validity of variables before using them (which is something you can often see in programs of all types) but did not know how to accomplish this in SPSS. Of course the original SAS-like syntax would not work even in SAS.

Best regards,

Jan



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Tuesday, May 11, 2010 4:09 PM
To: [hidden email]
Subject: Re: IF sentence

Hi Jan,

Yes, I understand what you are saying about what I posted. My code doesn't make sense. Did I misunderstand the meaning of the '.' in the original statement? If so, then it seems like there is a logic error in Elina's original code.

Gene Maguin



I am very sorry Gene, but your code probably does not work as Elina thinks.
If a variable is missing, you cannot compute a difference with it. :-) Therefore I guess that Elina wishes to test whether the variables are _not_ missing.

Best regards,

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Tuesday, May 11, 2010 3:37 PM
To: [hidden email]
Subject: Re: IF sentence

Elina,

It almost looks like you are writing sas syntax and not spss syntax. So, I guessing that 'if pvm.11 =.' means do what follows if pvm.ll is missing. You need to do some reading in the syntax reference for the following commands and keywords: Do if-End if, Sysmis (as a function), If, and Compute.

In spss the following would be

DO IF (sysmis(Pvm.11)).
+  COMPUTE mt = (Pvm.11 - Pvm.1).
ELSE IF (SYSMIS(Pvm.10)).
+  COMPUTE mt = (Pvm.10 - Pvm.1).
ELSE IF (SYSMIS(Pvm.9)).
+  COMPUTE mt = (Pvm.9 - Pvm.1).
ELSE IF (SYSMIS(Pvm.8)).
+  COMPUTE mt = (Pvm.8- Pvm.1).
ELSE IF (SYSMIS(Pvm.7)).
+  COMPUTE mt = (Pvm.7 - Pvm.1).
ELSE IF (SYSMIS(Pvm.6)).
+  COMPUTE mt = (Pvm.6 - Pvm.1).
ELSE IF (SYSMIS(Pvm.5)).
+  COMPUTE mt = (Pvm.5 - Pvm.1).
ELSE IF (SYSMIS(Pvm.4)).
+  COMPUTE mt = (Pvm.4 - Pvm.1).
ELSE IF (SYSMIS(Pvm.3)).
+  COMPUTE mt = (Pvm.3 - Pvm.1).
ELSE IF (SYSMIS(Pvm.2)).
+  COMPUTE mt = (Pvm.2 - Pvm.1).
ELSE.
+  COMPUTE mt = 0.
END IF.
EXECUTE.


Now, if you do some more reading and read about the Do repeat-End repeat command structure you can simplify things greatly.

DO REPEAT X=Pvm.2 Pvm.3 Pvm.4 Pvm.5 Pvm.6 Pvm.7 Pvm.8 Pvm.9 Pvm.10 Pvm.11.
+  COMPUTE mt = 0.
+  IF (sysmis(X)) mt = (X - Pvm.1).
END REPEAT.
EXECUTE.

Gene Maguin


>>Hi, can anyone tell me what is wrong with this

IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
ELSE IF mt = 0.
EXECUTE.

And how to fix it.

-Elina from Finland

=====================
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



_____________
Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --

=====================
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: IF sentence

Art Kendall
In reply to this post by Elina Tenhunen
do you mean to subtract pvm.1 from the other variables unless the other
variable is missing,?
then something like one of these untested syntax sets would do it.  Is
there a reason pvm.nn is in descending order?


do repeat oldvar = pvm.2 to pvm.11/newvar= newpvm.2 to newpvm.11.
do if missing(oldvar) .
compute newvar =-999999.
else.
compute newvar = oldvar-pvm.1.
end if.
end repeat.
missing values newpvm.2 to newpvm.11(-999999).


compute mt= -999998.
do repeat oldvar = pvm.11 pvm.10 pvm.9 pvm.8 pvm.7 pvm.6 pvm.5 pvm.4
pvm.3 pvm.2
do if missing(oldvar) .
compute mt =-999999.
else.
compute newvar = oldvar-pvm.1.
end if.
end repeat.
missing values mt(-999998, -999999).
value labels
  mt -999998 'initialized value'
     -999999 'assigned value'.


compute mt= -999998.
vector pvm = pvm.2 to pvm.11.
loop #i = 11 to 2 by -1.
if missing (pvm(#i).
compute mt = -999999.
else.
compute mt= pvm(#i) - pvm.1.
end if.
end loop.
missing values mt(-999998, -999999).
value labels
  mt -999998 'initialized value'
     -999999 'assigned value'.

Art Kendall
Social Research Consultants

On 5/11/2010 9:09 AM, Elina Tenhunen wrote:

> Hi, can anyone tell me what is wrong with this
>
> IF Pvm.11 =. Then mt = (Pvm.11 - Pvm.1).
> ELSE IF  Pvm.10 =. Then  mt = (Pvm.10 - Pvm.1).
> ELSE IF Pvm.9 =.Then mt = (Pvm.9 - Pvm.1).
> ELSE IF Pvm.8 =.Then mt = (Pvm.8- Pvm.1).
> ELSE IF Pvm7 =. Then mt = (Pvm.7 - Pvm.1).
> ELSE IF Pvm.6 =.Then mt = (Pvm.6 - Pvm.1).
> ELSE IF Pvm.5 =.Then mt = (Pvm.5 - Pvm.1).
> ELSE IF Pvm.4 =. Then mt =  (Pvm.4 - Pvm.1).
> ELSE IF Pvm.3 =. Then mt = (Pvm.3 - Pvm.1).
> ELSE IF Pvm.2 =. Then mt = (Pvm.2 - Pvm.1).
> ELSE IF mt = 0.
> EXECUTE.
>
> And how to fix it.
>
> -Elina from Finland
>
> =====================
> 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: IF sentence

Elina Tenhunen
In reply to this post by Elina Tenhunen
Hi,
Thank you for helping me!

This is how actually got it to work.

DO IF (not missing(Pvm.11)).
- COMPUTE mt = DATEDIFF(Pvm.11,Pvm.1,"days").
ELSE IF  (not missing(Pvm.10)).
- COMPUTE mt = DATEDIFF(Pvm.10,Pvm.1,"days").
ELSE IF  (not missing(Pvm.9)).
- COMPUTE mt = DATEDIFF(Pvm.9,Pvm.1,"days").
ELSE IF  (not missing(Pvm.8)).
- COMPUTE mt = DATEDIFF(Pvm.8,Pvm.1,"days").
ELSE IF  (not missing(Pvm.7)).
- COMPUTE mt = DATEDIFF(Pvm.7,Pvm.1,"days").
ELSE IF  (not missing(Pvm.6)).
- COMPUTE mt = DATEDIFF(Pvm.6,Pvm.1,"days").
ELSE IF (not missing(Pvm.5)).
- COMPUTE mt = DATEDIFF(Pvm.5,Pvm.1,"days").
ELSE IF (not missing(Pvm.4)).
- COMPUTE mt = DATEDIFF(Pvm.4,Pvm.1,"days").
ELSE IF (not missing(Pvm.3)).
- COMPUTE mt = DATEDIFF(Pvm.3,Pvm.1,"days").
ELSE IF (not missing(Pvm.3)).
- COMPUTE mt = DATEDIFF(Pvm.2,Pvm.1,"days").
ELSE .
  COMPUTE mt = 0.
END IF.
EXECUTE.

(In finnish pvm means date and mt is for follow up time)
I wanted to account how many days this peole have been in our "follow up".

And actually I still have problem. Some of them are still coming to checkups
so there will Pvm.12, Pvm.13 etc
Is it possible to make somekind of Max(Pvm) Variable?
So I don't have write a new code for everytime I want to see how long they
have been in follow up.

And this is how the data could look like:

ID    Pvm.1          Pvm.2           Pvm.3            Pvm.4      ect.
 1  01.07.2007 12.10.2007 12.11.2007 12.02.2008
 2 09.10.2008
 3 14.02.2007
 4 16.11.2008
 . 12.03.2008
 . 09.05.2008 22.09.2008
 31.12.2008 24.04.2009 03.09.2009
 12.10.2009
 13.02.2010 13.02.2010
 10.02.2007 12.05.2007 12.09.2007 12.03.2008
 20.09.2002 03.01.2003 11.02.2003 01.04.2003
 26.05.2006 12.11.2006 01.02.2007 02.03.2007
 30.11.2004 11.03.2005 11.04.2005 11.05.2005
 21.08.2007 11.10.2007 12.12.2007

Sorry abouth my terrible english :)
Best,
Elina

=====================
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: IF sentence

Spousta Jan
Yes, Elina, it is possible to compute maxima from variables. Perhaps your complicated logic can reduce into one row in this way:

COMPUTE mt = DATEDIFF(MAX(Pvm.1, Pvm.2, Pvm.3, ...), Pvm.1, "days").
/* update the list of variables / arguments of MAX(.) - you can perhaps use the easier form "MAX(Pvm.1 TO Pvm.11)" */ EXECUTE.

You need no testing of missings here, because the maximum is always valid in this case, since you have at least Pvm.1 valid.

Best regards,

Jan

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Elina Tenhunen
Sent: Tuesday, May 11, 2010 5:04 PM
To: [hidden email]
Subject: Re: IF sentence

Hi,
Thank you for helping me!

This is how actually got it to work.

DO IF (not missing(Pvm.11)).
- COMPUTE mt = DATEDIFF(Pvm.11,Pvm.1,"days").
ELSE IF  (not missing(Pvm.10)).
- COMPUTE mt = DATEDIFF(Pvm.10,Pvm.1,"days").
ELSE IF  (not missing(Pvm.9)).
- COMPUTE mt = DATEDIFF(Pvm.9,Pvm.1,"days").
ELSE IF  (not missing(Pvm.8)).
- COMPUTE mt = DATEDIFF(Pvm.8,Pvm.1,"days").
ELSE IF  (not missing(Pvm.7)).
- COMPUTE mt = DATEDIFF(Pvm.7,Pvm.1,"days").
ELSE IF  (not missing(Pvm.6)).
- COMPUTE mt = DATEDIFF(Pvm.6,Pvm.1,"days").
ELSE IF (not missing(Pvm.5)).
- COMPUTE mt = DATEDIFF(Pvm.5,Pvm.1,"days").
ELSE IF (not missing(Pvm.4)).
- COMPUTE mt = DATEDIFF(Pvm.4,Pvm.1,"days").
ELSE IF (not missing(Pvm.3)).
- COMPUTE mt = DATEDIFF(Pvm.3,Pvm.1,"days").
ELSE IF (not missing(Pvm.3)).
- COMPUTE mt = DATEDIFF(Pvm.2,Pvm.1,"days").
ELSE .
  COMPUTE mt = 0.
END IF.
EXECUTE.

(In finnish pvm means date and mt is for follow up time) I wanted to account how many days this peole have been in our "follow up".

And actually I still have problem. Some of them are still coming to checkups so there will Pvm.12, Pvm.13 etc Is it possible to make somekind of Max(Pvm) Variable?
So I don't have write a new code for everytime I want to see how long they have been in follow up.

And this is how the data could look like:

ID    Pvm.1          Pvm.2           Pvm.3            Pvm.4      ect.
 1  01.07.2007 12.10.2007 12.11.2007 12.02.2008
 2 09.10.2008
 3 14.02.2007
 4 16.11.2008
 . 12.03.2008
 . 09.05.2008 22.09.2008
 31.12.2008 24.04.2009 03.09.2009
 12.10.2009
 13.02.2010 13.02.2010
 10.02.2007 12.05.2007 12.09.2007 12.03.2008
 20.09.2002 03.01.2003 11.02.2003 01.04.2003
 26.05.2006 12.11.2006 01.02.2007 02.03.2007
 30.11.2004 11.03.2005 11.04.2005 11.05.2005
 21.08.2007 11.10.2007 12.12.2007

Sorry abouth my terrible english :)
Best,
Elina

=====================
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



_____________
Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.

Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --

=====================
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: IF sentence

David Marso
Administrator
In reply to this post by Elina Tenhunen
VERY NICE Jan !!!!
On Wed, 12 May 2010 09:55:47 +0200, Spousta Jan <[hidden email]> wrote:

>Yes, Elina, it is possible to compute maxima from variables. Perhaps your
complicated logic can reduce into one row in this way:
>
>COMPUTE mt = DATEDIFF(MAX(Pvm.1, Pvm.2, Pvm.3, ...), Pvm.1, "days").
>/* update the list of variables / arguments of MAX(.) - you can perhaps use
the easier form "MAX(Pvm.1 TO Pvm.11)" */ EXECUTE.
>
>You need no testing of missings here, because the maximum is always valid
in this case, since you have at least Pvm.1 valid.
>
>Best regards,
>
>Jan
>
>-----Original Message-----
>From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Elina Tenhunen

>Sent: Tuesday, May 11, 2010 5:04 PM
>To: [hidden email]
>Subject: Re: IF sentence
>
>Hi,
>Thank you for helping me!
>
>This is how actually got it to work.
>
>DO IF (not missing(Pvm.11)).
>- COMPUTE mt = DATEDIFF(Pvm.11,Pvm.1,"days").
>ELSE IF  (not missing(Pvm.10)).
>- COMPUTE mt = DATEDIFF(Pvm.10,Pvm.1,"days").
>ELSE IF  (not missing(Pvm.9)).
>- COMPUTE mt = DATEDIFF(Pvm.9,Pvm.1,"days").
>ELSE IF  (not missing(Pvm.8)).
>- COMPUTE mt = DATEDIFF(Pvm.8,Pvm.1,"days").
>ELSE IF  (not missing(Pvm.7)).
>- COMPUTE mt = DATEDIFF(Pvm.7,Pvm.1,"days").
>ELSE IF  (not missing(Pvm.6)).
>- COMPUTE mt = DATEDIFF(Pvm.6,Pvm.1,"days").
>ELSE IF (not missing(Pvm.5)).
>- COMPUTE mt = DATEDIFF(Pvm.5,Pvm.1,"days").
>ELSE IF (not missing(Pvm.4)).
>- COMPUTE mt = DATEDIFF(Pvm.4,Pvm.1,"days").
>ELSE IF (not missing(Pvm.3)).
>- COMPUTE mt = DATEDIFF(Pvm.3,Pvm.1,"days").
>ELSE IF (not missing(Pvm.3)).
>- COMPUTE mt = DATEDIFF(Pvm.2,Pvm.1,"days").
>ELSE .
>  COMPUTE mt = 0.
>END IF.
>EXECUTE.
>
>(In finnish pvm means date and mt is for follow up time) I wanted to
account how many days this peole have been in our "follow up".
>
>And actually I still have problem. Some of them are still coming to
checkups so there will Pvm.12, Pvm.13 etc Is it possible to make somekind of
Max(Pvm) Variable?
>So I don't have write a new code for everytime I want to see how long they
have been in follow up.

>
>And this is how the data could look like:
>
>ID    Pvm.1          Pvm.2           Pvm.3            Pvm.4      ect.
> 1  01.07.2007 12.10.2007 12.11.2007 12.02.2008
> 2 09.10.2008
> 3 14.02.2007
> 4 16.11.2008
> . 12.03.2008
> . 09.05.2008 22.09.2008
> 31.12.2008 24.04.2009 03.09.2009
> 12.10.2009
> 13.02.2010 13.02.2010
> 10.02.2007 12.05.2007 12.09.2007 12.03.2008
> 20.09.2002 03.01.2003 11.02.2003 01.04.2003
> 26.05.2006 12.11.2006 01.02.2007 02.03.2007
> 30.11.2004 11.03.2005 11.04.2005 11.05.2005
> 21.08.2007 11.10.2007 12.12.2007
>
>Sorry abouth my terrible english :)
>Best,
>Elina
>
>=====================
>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
>
>
>
>_____________
>Tato zpr�va a v�echny p�ipojen� soubory jsou d�v�rn� a ur�en� v�lu�n�
adres�tovi(-�m). Jestli�e nejste opr�vn�n�m adres�tem, je zak�z�no jak�koliv
zve�ej�ov�n�, zprost�edkov�n� nebo jin� pou�it� t�chto informac�. Jestli�e
jste tento mail dostali neopr�vn�n�, pros�m, uv�domte odesilatele a sma�te
zpr�vu i p�ilo�en� soubory. Odesilatel nezodpov�d� za jak�koliv chyby nebo
opomenut� zp�soben� t�mto p�enosem.
>
>Jste si jisti, �e opravdu pot�ebujete vytisknout tuto zpr�vu a/nebo jej�
p��lohy? Myslete na p��rodu.
>
>
>This message and any attached files are confidential and intended solely
for the addressee(s). Any publication, transmission or other use of the
information by a person or entity other than the intended addressee is
prohibited. If you receive this in error please contact the sender and
delete the message as well as all attached documents. The sender does not
accept liability for any errors or omissions as a result of the transmission.
>
>Are you sure that you really need a print version of this message and/or
its attachments? Think about nature.

>
>-.- --
>
>=====================
>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
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?"