assigning values

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

assigning values

Zdaniuk, Bozena-3

hello, my dear fellow spss'ers. I have a file that looks something like this:

ID        Var1    Var2    Var3
001    ...        ....        3.0
002    2.4        ....        ...
003    ...        4.5        ...
004    ...        3.7        6.7
005    2.0        4.1        ..

Dots represent system missing values. Var 1-3 represent times at which the values were collected with Var 1 being the earliest. I would like to create Var 4 that will contain the value that appears earliest for each case. So, I would like to get something like this:

ID        Var4 
001    3.0     
002    2.4       
003   4.5      
004    3.7 
005    2.0   
I know how to do it with a whole bunch of COMPUTE and IF sentences but i wonder if someone could suggest an easier and less clunky way...
thanks so much.
bozena

Reply | Threaded
Open this post in threaded view
|

Re: assigning values

David Marso
Administrator
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  DO IF NOT(MISSING(V(#))).
+    COMPUTE Var4=V(#).
+    BREAK.
+  END IF.
END LOOP.
LIST.

Zdaniuk, Bozena-3 wrote
hello, my dear fellow spss'ers. I have a file that looks something like this:

ID        Var1    Var2    Var3
001    ...        ....        3.0
002    2.4        ....        ...
003    ...        4.5        ...
004    ...        3.7        6.7
005    2.0        4.1        ..

Dots represent system missing values. Var 1-3 represent times at which the values were collected with Var 1 being the earliest. I would like to create Var 4 that will contain the value that appears earliest for each case. So, I would like to get something like this:

ID        Var4
001    3.0
002    2.4
003   4.5
004    3.7
005    2.0
I know how to do it with a whole bunch of COMPUTE and IF sentences but i wonder if someone could suggest an easier and less clunky way...
thanks so much.
bozena
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: assigning values

David Marso
Administrator

Or even tidier:
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  IF NOT(MISSING(V(#))) Var4=V(#).
END LOOP IF NOT MISSING(Var4).
LIST.

David Marso wrote
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  DO IF NOT(MISSING(V(#))).
+    COMPUTE Var4=V(#).
+    BREAK.
+  END IF.
END LOOP.
LIST.

Zdaniuk, Bozena-3 wrote
hello, my dear fellow spss'ers. I have a file that looks something like this:

ID        Var1    Var2    Var3
001    ...        ....        3.0
002    2.4        ....        ...
003    ...        4.5        ...
004    ...        3.7        6.7
005    2.0        4.1        ..

Dots represent system missing values. Var 1-3 represent times at which the values were collected with Var 1 being the earliest. I would like to create Var 4 that will contain the value that appears earliest for each case. So, I would like to get something like this:

ID        Var4
001    3.0
002    2.4
003   4.5
004    3.7
005    2.0
I know how to do it with a whole bunch of COMPUTE and IF sentences but i wonder if someone could suggest an easier and less clunky way...
thanks so much.
bozena
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: assigning values

David Marso
Administrator
OR:
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  COMPUTE Var4=V(#).
END LOOP IF NOT MISSING(Var4).
LIST.

David Marso wrote
Or even tidier:
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  IF NOT(MISSING(V(#))) Var4=V(#).
END LOOP IF NOT MISSING(Var4).
LIST.

David Marso wrote
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  DO IF NOT(MISSING(V(#))).
+    COMPUTE Var4=V(#).
+    BREAK.
+  END IF.
END LOOP.
LIST.

Zdaniuk, Bozena-3 wrote
hello, my dear fellow spss'ers. I have a file that looks something like this:

ID        Var1    Var2    Var3
001    ...        ....        3.0
002    2.4        ....        ...
003    ...        4.5        ...
004    ...        3.7        6.7
005    2.0        4.1        ..

Dots represent system missing values. Var 1-3 represent times at which the values were collected with Var 1 being the earliest. I would like to create Var 4 that will contain the value that appears earliest for each case. So, I would like to get something like this:

ID        Var4
001    3.0
002    2.4
003   4.5
004    3.7
005    2.0
I know how to do it with a whole bunch of COMPUTE and IF sentences but i wonder if someone could suggest an easier and less clunky way...
thanks so much.
bozena
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: assigning values

Zdaniuk, Bozena-3
David, that's great! thanks so much. Would you be willing to also suggest the syntax if I wanted the latest valid value rather than the earliest? (i may have to pull both of those...).
bozena
________________________________________
From: SPSSX(r) Discussion [[hidden email]] on behalf of David Marso [[hidden email]]
Sent: Friday, May 11, 2012 12:37 PM
To: [hidden email]
Subject: Re: assigning values

OR:
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  COMPUTE Var4=V(#).
END LOOP IF NOT MISSING(Var4).
LIST.


David Marso wrote

>
> Or even tidier:
> VECTOR V=Var1 TO Var3.
> LOOP #=1 TO 3.
> +  IF NOT(MISSING(V(#))) Var4=V(#).
> END LOOP IF NOT MISSING(Var4).
> LIST.
>
>
> David Marso wrote
>>
>> VECTOR V=Var1 TO Var3.
>> LOOP #=1 TO 3.
>> +  DO IF NOT(MISSING(V(#))).
>> +    COMPUTE Var4=V(#).
>> +    BREAK.
>> +  END IF.
>> END LOOP.
>> LIST.
>>
>>
>> Zdaniuk, Bozena-3 wrote
>>>
>>> hello, my dear fellow spss'ers. I have a file that looks something like
>>> this:
>>>
>>> ID        Var1    Var2    Var3
>>> 001    ...        ....        3.0
>>> 002    2.4        ....        ...
>>> 003    ...        4.5        ...
>>> 004    ...        3.7        6.7
>>> 005    2.0        4.1        ..
>>>
>>> Dots represent system missing values. Var 1-3 represent times at which
>>> the values were collected with Var 1 being the earliest. I would like to
>>> create Var 4 that will contain the value that appears earliest for each
>>> case. So, I would like to get something like this:
>>>
>>> ID        Var4
>>> 001    3.0
>>> 002    2.4
>>> 003   4.5
>>> 004    3.7
>>> 005    2.0
>>> I know how to do it with a whole bunch of COMPUTE and IF sentences but i
>>> wonder if someone could suggest an easier and less clunky way...
>>> thanks so much.
>>> bozena
>>>
>>
>


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/assigning-values-tp5703875p5704273.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

=====================
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: assigning values

Rick Oliver-3
LOOP #=3 to 1.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]
Phone: 312.893.4922 | T/L: 206-4922




From:        "Zdaniuk, Bozena" <[hidden email]>
To:        [hidden email]
Date:        05/11/2012 04:09 PM
Subject:        Re: assigning values
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




David, that's great! thanks so much. Would you be willing to also suggest the syntax if I wanted the latest valid value rather than the earliest? (i may have to pull both of those...).
bozena
________________________________________
From: SPSSX(r) Discussion [[hidden email]] on behalf of David Marso [[hidden email]]
Sent: Friday, May 11, 2012 12:37 PM
To: [hidden email]
Subject: Re: assigning values

OR:
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  COMPUTE Var4=V(#).
END LOOP IF NOT MISSING(Var4).
LIST.


David Marso wrote
>
> Or even tidier:
> VECTOR V=Var1 TO Var3.
> LOOP #=1 TO 3.
> +  IF NOT(MISSING(V(#))) Var4=V(#).
> END LOOP IF NOT MISSING(Var4).
> LIST.
>
>
> David Marso wrote
>>
>> VECTOR V=Var1 TO Var3.
>> LOOP #=1 TO 3.
>> +  DO IF NOT(MISSING(V(#))).
>> +    COMPUTE Var4=V(#).
>> +    BREAK.
>> +  END IF.
>> END LOOP.
>> LIST.
>>
>>
>> Zdaniuk, Bozena-3 wrote
>>>
>>> hello, my dear fellow spss'ers. I have a file that looks something like
>>> this:
>>>
>>> ID        Var1    Var2    Var3
>>> 001    ...        ....        3.0
>>> 002    2.4        ....        ...
>>> 003    ...        4.5        ...
>>> 004    ...        3.7        6.7
>>> 005    2.0        4.1        ..
>>>
>>> Dots represent system missing values. Var 1-3 represent times at which
>>> the values were collected with Var 1 being the earliest. I would like to
>>> create Var 4 that will contain the value that appears earliest for each
>>> case. So, I would like to get something like this:
>>>
>>> ID        Var4
>>> 001    3.0
>>> 002    2.4
>>> 003   4.5
>>> 004    3.7
>>> 005    2.0
>>> I know how to do it with a whole bunch of COMPUTE and IF sentences but i
>>> wonder if someone could suggest an easier and less clunky way...
>>> thanks so much.
>>> bozena
>>>
>>
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/assigning-values-tp5703875p5704273.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

=====================
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: assigning values

David Marso
Administrator
LOOP #=3 to 1 BY -1.
Rick Oliver wrote
LOOP #=3 to 1.


Rick Oliver
Senior Information Developer
IBM Business Analytics (SPSS)
E-mail: [hidden email]
Phone: 312.893.4922 | T/L: 206-4922



From:   "Zdaniuk, Bozena" <[hidden email]>
To:     [hidden email]
Date:   05/11/2012 04:09 PM
Subject:        Re: assigning values
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



David, that's great! thanks so much. Would you be willing to also suggest
the syntax if I wanted the latest valid value rather than the earliest? (i
may have to pull both of those...).
bozena
________________________________________
From: SPSSX(r) Discussion [[hidden email]] on behalf of David
Marso [[hidden email]]
Sent: Friday, May 11, 2012 12:37 PM
To: [hidden email]
Subject: Re: assigning values

OR:
VECTOR V=Var1 TO Var3.
LOOP #=1 TO 3.
+  COMPUTE Var4=V(#).
END LOOP IF NOT MISSING(Var4).
LIST.


David Marso wrote
>
> Or even tidier:
> VECTOR V=Var1 TO Var3.
> LOOP #=1 TO 3.
> +  IF NOT(MISSING(V(#))) Var4=V(#).
> END LOOP IF NOT MISSING(Var4).
> LIST.
>
>
> David Marso wrote
>>
>> VECTOR V=Var1 TO Var3.
>> LOOP #=1 TO 3.
>> +  DO IF NOT(MISSING(V(#))).
>> +    COMPUTE Var4=V(#).
>> +    BREAK.
>> +  END IF.
>> END LOOP.
>> LIST.
>>
>>
>> Zdaniuk, Bozena-3 wrote
>>>
>>> hello, my dear fellow spss'ers. I have a file that looks something
like
>>> this:
>>>
>>> ID        Var1    Var2    Var3
>>> 001    ...        ....        3.0
>>> 002    2.4        ....        ...
>>> 003    ...        4.5        ...
>>> 004    ...        3.7        6.7
>>> 005    2.0        4.1        ..
>>>
>>> Dots represent system missing values. Var 1-3 represent times at which
>>> the values were collected with Var 1 being the earliest. I would like
to
>>> create Var 4 that will contain the value that appears earliest for
each
>>> case. So, I would like to get something like this:
>>>
>>> ID        Var4
>>> 001    3.0
>>> 002    2.4
>>> 003   4.5
>>> 004    3.7
>>> 005    2.0
>>> I know how to do it with a whole bunch of COMPUTE and IF sentences but
i
>>> wonder if someone could suggest an easier and less clunky way...
>>> thanks so much.
>>> bozena
>>>
>>
>


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/assigning-values-tp5703875p5704273.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

=====================
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: assigning values

David Marso
Administrator
And now ponder this ;-)
DATA LIST LIST /ID V1 TO V3 W1 TO W4 X1 TO X5.
BEGIN DATA
001     .   .  3.0   1.0 .   .  .   .   .  . . . 3.0
002    2.4  .   .     . 2.0 3.0 .  1.0  .  . . . 5.0
003     .  4.5  .     .  .   . 4.0  .  3.0 . . .  .  
004     .  3.7 6.7   2.0 3.5 .  .   .   . 2.0  .  .
005    2.0 4.1  .    6.0  .  . 7.0  .  1.0 .   . 5.3
END DATA.
DO REPEAT F= V1 W1 X1 / L=V3 W4 X5 / NF= VFirst WFirst XFirst/ NL=VLast WLast XLast/VEC=V W X .
+  COMPUTE #SIZE=SUM(NVALID(F TO L),NMISS(F TO L)).
+  VECTOR VEC=F TO L.
+  LOOP #=1 TO #SIZE.
+    COMPUTE NF=VEC(#).
+  END LOOP IF NOT MISSING(NF).
+  LOOP #= #SIZE TO 1 BY -1.
+    COMPUTE NL=VEC(#).
+  END LOOP IF NOT MISSING(NL).
END REPEAT.
LIST.
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: assigning values

Zdaniuk, Bozena-3
I am speechless :)
thanks so much for all this help. Works like a charm.
bozena
________________________________________
From: SPSSX(r) Discussion [[hidden email]] on behalf of David Marso [[hidden email]]
Sent: Friday, May 11, 2012 3:39 PM
To: [hidden email]
Subject: Re: assigning values

And now ponder this ;-)
DATA LIST LIST /ID V1 TO V3 W1 TO W4 X1 TO X5.
BEGIN DATA
001     .   .  3.0   1.0 .   .  .   .   .  . . . 3.0
002    2.4  .   .     . 2.0 3.0 .  1.0  .  . . . 5.0
003     .  4.5  .     .  .   . 4.0  .  3.0 . . .  .
004     .  3.7 6.7   2.0 3.5 .  .   .   . 2.0  .  .
005    2.0 4.1  .    6.0  .  . 7.0  .  1.0 .   . 5.3
END DATA.
DO REPEAT F= V1 W1 X1 / L=V3 W4 X5 / NF= VFirst WFirst XFirst/ NL=VLast
WLast XLast/VEC=V W X .
+  COMPUTE #SIZE=SUM(NVALID(F TO L),NMISS(F TO L)).
+  VECTOR VEC=F TO L.
+  LOOP #=1 TO #SIZE.
+    COMPUTE NF=VEC(#).
+  END LOOP IF NOT MISSING(NF).
+  LOOP #= #SIZE TO 1 BY -1.
+    COMPUTE NL=VEC(#).
+  END LOOP IF NOT MISSING(NL).
END REPEAT.
LIST.


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/assigning-values-tp5703875p5705892.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

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