Loop

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

Loop

joan casellas

Dear list,

 

I have the following syntax and I would like to do the same 10 times. I have to create a loop and change the value highlighted it yellow. Any suggestions?

 

 

compute q24rr1=$sysmis.

if (q23_1=1) q24rr1=q24r1.

if (sys(q24r1))q24rr1=$sysmis.

val lab q24rr 1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit' 4 'Great benefit'.

fre q24r1 q24rr1.

 

Any help would be really appreciated. Thanks in advance.

 

Joan

Reply | Threaded
Open this post in threaded view
|

Re: Loop

Spousta Jan
Joan,
 
what about

DO REPEAT rr = q24rr1 to q24rr10 / q23 = q23_1 to q23_10 / q24 = q24r1 to q24r10.
COMPUTE rr = $sysmis.
IF (q23=1) rr=q24.
IF (sys(q24)) rr=$sysmis.
END REPEAT.
 
val lab q24rr1 to  q24rr1 1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit' 4 'Great benefit'.
fre q24r1 to q24r10 q24rr1 to q24rr10.
 
Best rgds
 
Jan


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of joan casellas
Sent: Thursday, November 03, 2011 1:27 PM
To: [hidden email]
Subject: Loop

Dear list,

 

I have the following syntax and I would like to do the same 10 times. I have to create a loop and change the value highlighted it yellow. Any suggestions?

 

 

compute q24rr1=$sysmis.

if (q23_1=1) q24rr1=q24r1.

if (sys(q24r1))q24rr1=$sysmis.

val lab q24rr 1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit' 4 'Great benefit'.

fre q24r1 q24rr1.

 

Any help would be really appreciated. Thanks in advance.

 

Joan

 

_____________

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.

P 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.

 

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

-.- --
Reply | Threaded
Open this post in threaded view
|

Re: Loop

David Marso
Administrator
In reply to this post by joan casellas
Probably the simplest approach would be to use DO REPEAT:  You could use VECTORS and LOOP but that's like using a sledgehammer to kill a fly on the wall.
--
Assuming vars are in order (to save me from typing, list them out if they are not).

DO REPEAT CheckForOne=q23_1 TO q23_10
               / SourceVar=q24r1 TO q24r10
               / ResultVar=q24rr1 TO q24rr10 .

* Not needed /Some (Art, Myself ... would be appalled if this showed up in production code,
* User defined missing values exist for a reason)*  Besides, variable will DEFAULT to Sysmis *.
*compute ResultVar=$sysmis.

if (CheckForOne EQ 1) ResultVar=SourceVar.

* Unnecessary (Redundant to the above IF since ResultVar is SYSMIS by DEFAULT).
*if (SYSMIS(SourceVar))ResultVar=$sysmis.
*Assumes -999 is *NOT* a valid possible value for SourceVar/ResultVar *.
* Be careful if there ARE already user defined missing values for SourceVars *.
IF MISSING(ResultVar) ResultVar=-999.
VALUE LABELS ResultVar  
           1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit' 4 'Great benefit'
          -999 'Missing Check variable or source variable'.
END REPEAT.
---

joan casellas wrote
Dear list,



I have the following syntax and I would like to do the same 10 times. I have
to create a loop and change the value highlighted it yellow. Any
suggestions?





compute q24rr1=$sysmis.

if (q23_1=1) q24rr1=q24r1.

if (sys(q24r1))q24rr1=$sysmis.

val lab q24rr 1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit' 4
'Great benefit'.

fre q24r1 q24rr1.



Any help would be really appreciated. Thanks in advance.



Joan
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: Loop

joan casellas
Hi David,

I maybe should clarify the problem. Basically, I have two questions: q23
(with 10 options/statements) and q24 (showing options/statements selected in
q23) where people gave a score (1 to 5).

Before q24 there is a filter and it works like this:
If you select 2 options in q23 you will see these two options in q24
If you select more than 2 options in q23 you will see randomly two of these
selected options in q24
If you select just one option in q23, you will see in q24 this selected
option plus another randomly option from q24

I want to reclassify people that have selected just one option in q23 and
answered the option shown randomly in q24.

*Create a new variable:
 Compute newvariable=$sysmis.
*Select people that selected just one option and assign response from
q24:
 If (q23_1=1) newvariable=q24r.
*Treat 0 as missing
If (sys(q24r) newvariable=$sysmis.
*Labeling
val lab newvariable 1 'Very poor' 2 'Poor' 3 'Neither' 4 'Good' 5 'Very
good'..

I hope now it makes more sense.

Thanks in advance

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
David Marso
Sent: 03 November 2011 14:18
To: [hidden email]
Subject: Re: Loop

Probably the simplest approach would be to use DO REPEAT:  You could use
VECTORS and LOOP but that's like using a sledgehammer to kill a fly on the
wall.
--
Assuming vars are in order (to save me from typing, list them out if they
are not).

DO REPEAT CheckForOne=q23_1 TO q23_10
               / SourceVar=q24r1 TO q24r10
               / ResultVar=q24rr1 TO q24rr10 .

* Not needed /Some (Art, Myself ... would be appalled if this showed up in
production code,
* User defined missing values exist for a reason)*  Besides, variable will
DEFAULT to Sysmis *.
*compute ResultVar=$sysmis.

if (CheckForOne EQ 1) ResultVar=SourceVar.

* Unnecessary (Redundant to the above IF since ResultVar is SYSMIS by
DEFAULT).
*if (SYSMIS(SourceVar))ResultVar=$sysmis.
*Assumes -999 is *NOT* a valid possible value for SourceVar/ResultVar *.
* Be careful if there ARE already user defined missing values for SourceVars
*.
IF MISSING(ResultVar) ResultVar=-999.
VALUE LABELS ResultVar
           1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit' 4
'Great benefit'
          -999 'Missing Check variable or source variable'.
END REPEAT.
---


joan casellas wrote:

>
> Dear list,
>
>
>
> I have the following syntax and I would like to do the same 10 times. I
> have
> to create a loop and change the value highlighted it yellow. Any
> suggestions?
>
>
>
>
>
> compute q24rr1=$sysmis.
>
> if (q23_1=1) q24rr1=q24r1.
>
> if (sys(q24r1))q24rr1=$sysmis.
>
> val lab q24rr 1 'No benefit at all' 2 'Not much benefit' 3 'Some benefit'
> 4
> 'Great benefit'.
>
> fre q24r1 q24rr1.
>
>
>
> Any help would be really appreciated. Thanks in advance.
>
>
>
> Joan
>


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

Carlos Renato
In reply to this post by joan casellas
Dear Friend

    Questions Q23 are then formed by zeros and ones?
    The Q24 is so variable between 1 and 5?

Thanks..

Carlos Renato