Loop

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

Loop

emma78
I have a question regarding A loop:


I have a variable called V1, with codes from 1 to 6 (diferent groups). Each
person only belongs to one group.

And then I have for example 28 statements S1 to S28.  We do only have one
variable for a specific item but not this item for each group.

You can cross the V1 with the S1 to see the values for each group for item
1.But it would be better to have separate variables:


S1_group1
S1_group2
...

S28_group6



28*6=168 new variables

I tried it with the loop syntax and I get 3 Loops and then I get confused:
1 to 168
1 to 28
1 to 6

Can anybody help me:-)

Thank you!




--
Sent from: http://spssx-discussion.1045642.n5.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: Loop

Jon Peck
I am not sure that restructuring the data as you describe is really an improvement.  It prevents you from using the group as a BY variable in many procedures, including, for example, CTABLES and from using SPLIT FILES or FILTER/SELECT IF to analyze individual groups.

Furthermore, what would you want the values to be for, say, S1_group1 for cases not in group1?  You might just wind up with huge numbers of missing values that you would have to select out.

If you want to do a bunch of analyses separately for a group,  you could make a separate data file for each group using XSAVE or the SPSSINC SPLIT DATASET extension command, which can be installed via Extensions > Extension Hub.  You could iterate over the data file using SPSSINC PROCESS FILES if you want to group a bunch of procedure outputs for each group.  In contrast, SPLIT FILES would iterate over groups within each procedure you run.  PROCESS FILES can be a little confusing to set up, but it would be easy to use once you get it organized.

You would also need to deal with the fact that not all the variables would exist for each group, which means syntax that works for one might not work for another.

If you would describe the scenarios where you want to use this structure, we could provide more help.

On Tue, Jun 18, 2019 at 9:49 AM emma78 <[hidden email]> wrote:
I have a question regarding A loop:


I have a variable called V1, with codes from 1 to 6 (diferent groups). Each
person only belongs to one group.

And then I have for example 28 statements S1 to S28.  We do only have one
variable for a specific item but not this item for each group.

You can cross the V1 with the S1 to see the values for each group for item
1.But it would be better to have separate variables:


S1_group1
S1_group2
...

S28_group6



28*6=168 new variables

I tried it with the loop syntax and I get 3 Loops and then I get confused:
1 to 168
1 to 28
1 to 6

Can anybody help me:-)

Thank you!




--
Sent from: http://spssx-discussion.1045642.n5.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


--
Jon K Peck
[hidden email]

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

spss.giesel@yahoo.de
In reply to this post by emma78
Emma, is it this what you need?

* -------------------------------------------------------------- MACRO DEFINITION.
DEFINE !separate(!POS !CMDEND)
PRESERVE.
SET PRINTBACK = ON MPRINT = ON.
!DO !s !IN (!1)
!DO !group = 1 !TO 6
!LET !new = !CONCAT(!s,"_group",!group)
IF (V1 = !group) !new = !s.
APPLY DICTIONARY FROM * /SOURCE VAR = !s/TARGET VAR = !new.
!DOEND
!DOEND
RESTORE.
!ENDDEFINE.
* -------------------------------------------------------------- MACRO END.

* Call.
!separate S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13 S14 S15 S16 S17 S18 S19 S20 S21 S22 S23 S24 S25 S26 S27 S28.

* --------------------------------------------------------------.

Mario Giesel
Munich, Germany


Am Dienstag, 18. Juni 2019, 17:49:43 MESZ hat emma78 <[hidden email]> Folgendes geschrieben:


I have a question regarding A loop:


I have a variable called V1, with codes from 1 to 6 (diferent groups). Each
person only belongs to one group.

And then I have for example 28 statements S1 to S28.  We do only have one
variable for a specific item but not this item for each group.

You can cross the V1 with the S1 to see the values for each group for item
1.But it would be better to have separate variables:


S1_group1
S1_group2
...

S28_group6



28*6=168 new variables

I tried it with the loop syntax and I get 3 Loops and then I get confused:
1 to 168
1 to 28
1 to 6

Can anybody help me:-)

Thank you!




--

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

Bruce Weaver
Administrator
In reply to this post by Jon Peck
I agree with Jon.  Your original post looks like it ~could~ be an example of
the XY problem.  

http://xyproblem.info/



Jon Peck wrote
> --- snip ---
> If you would describe the scenarios where you want to use this structure,
> we could provide more help.
>
> On Tue, Jun 18, 2019 at 9:49 AM emma78 &lt;

> claudia.weitkowitz@

> &gt;
> wrote:
>
>> I have a question regarding A loop:
>>
>>
>> I have a variable called V1, with codes from 1 to 6 (diferent groups).
>> Each
>> person only belongs to one group.
>>
>> And then I have for example 28 statements S1 to S28.  We do only have one
>> variable for a specific item but not this item for each group.
>>
>> You can cross the V1 with the S1 to see the values for each group for
>> item
>> 1.But it would be better to have separate variables:
>>
>>
>> S1_group1
>> S1_group2
>> ...
>>
>> S28_group6
>>
>>
>>
>> 28*6=168 new variables
>>
>> I tried it with the loop syntax and I get 3 Loops and then I get
>> confused:
>> 1 to 168
>> 1 to 28
>> 1 to 6
>>
>> Can anybody help me:-)
>>
>> Thank you!
>>





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

--
Sent from: http://spssx-discussion.1045642.n5.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
--
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: Loop

spss.giesel@yahoo.de
Sometimes it is just a programming issue that makes this necessary.
If you have a parameterized question that refers to an earlier question like
"Why do you find brand X [good/bad]?"
you have answers to different questions placed within the same variable.
In that case a separation is indeed necessary.

The macro above only works for numeric variables, though.


Mario Giesel
Munich, Germany


Am Dienstag, 18. Juni 2019, 23:45:02 MESZ hat Bruce Weaver <[hidden email]> Folgendes geschrieben:


I agree with Jon.  Your original post looks like it ~could~ be an example of
the XY problem. 

http://xyproblem.info/



Jon Peck wrote
> --- snip ---
> If you would describe the scenarios where you want to use this structure,
> we could provide more help.
>
> On Tue, Jun 18, 2019 at 9:49 AM emma78 &lt;

> claudia.weitkowitz@

> &gt;
> wrote:
>
>> I have a question regarding A loop:
>>
>>
>> I have a variable called V1, with codes from 1 to 6 (diferent groups).
>> Each
>> person only belongs to one group.
>>
>> And then I have for example 28 statements S1 to S28.  We do only have one
>> variable for a specific item but not this item for each group.
>>
>> You can cross the V1 with the S1 to see the values for each group for
>> item
>> 1.But it would be better to have separate variables:
>>
>>
>> S1_group1
>> S1_group2
>> ...
>>
>> S28_group6
>>
>>
>>
>> 28*6=168 new variables
>>
>> I tried it with the loop syntax and I get 3 Loops and then I get
>> confused:
>> 1 to 168
>> 1 to 28
>> 1 to 6
>>
>> Can anybody help me:-)
>>
>> Thank you!
>>





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


--
Sent from: http://spssx-discussion.1045642.n5.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

emma78
It is exactly as Mario said, it is a programming question.
And sometimes the client needs the data in another format and we have to
deliver :-)

I will test your macro, thank you!



--
Sent from: http://spssx-discussion.1045642.n5.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: Loop

Robert L
In reply to this post by emma78
Or is it a multiple response kind of problem? What is the distribution of answers for each statement for each group?

Robert

-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För emma78
Skickat: den 18 juni 2019 17:50
Till: [hidden email]
Ämne: Loop

I have a question regarding A loop:


I have a variable called V1, with codes from 1 to 6 (diferent groups). Each
person only belongs to one group.

And then I have for example 28 statements S1 to S28.  We do only have one
variable for a specific item but not this item for each group.

You can cross the V1 with the S1 to see the values for each group for item
1.But it would be better to have separate variables:


S1_group1
S1_group2
...

S28_group6



28*6=168 new variables

I tried it with the loop syntax and I get 3 Loops and then I get confused:
1 to 168
1 to 28
1 to 6

Can anybody help me:-)

Thank you!




--
Sent from: http://spssx-discussion.1045642.n5.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
Robert Lundqvist
Reply | Threaded
Open this post in threaded view
|

Re: Loop

emma78
Each person sees all statements, but for a different brand (group)



--
Sent from: http://spssx-discussion.1045642.n5.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: Loop

David Marso-2
In reply to this post by emma78
Slightly different but same result.

DEFINE !separate(!POS !CMDEND)
PRESERVE.
SET PRINTBACK = ON MPRINT = ON.
!DO !s !IN (!1)
VECTOR !CONCAT(!s,"_group(6)").
RECODE
   !CONCAT(!s,"_group1 TO ",!s,"_group6) (ELSE=0).
COMPUTE !CONCAT(!s,"_group(V1)"= !s.
APPLY DICTIONARY FROM * /SOURCE VAR = !s/TARGET VAR = !CONCAT(!s,"_group1 TO ",!s,"_group6) .
DOEND
RESTORE.
!ENDDEFINE.

ORIGINAL FOR CONTEXT.

"DEFINE !separate(!POS !CMDEND)
PRESERVE.
SET PRINTBACK = ON MPRINT = ON.
!DO !s !IN (!1)
!DO !group = 1 !TO 6
!LET !new = !CONCAT(!s,"_group",!group)
IF (V1 = !group) !new = !s.
APPLY DICTIONARY FROM * /SOURCE VAR = !s/TARGET VAR = !new.
!DOEND
!DOEND
RESTORE.
!ENDDEFINE.

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

spss.giesel@yahoo.de
Just add an exclamation mark here:
DOEND => !DOEND

Mario Giesel
Munich, Germany


Am Donnerstag, 20. Juni 2019, 20:55:11 MESZ hat David Marso <[hidden email]> Folgendes geschrieben:


Slightly different but same result.

DEFINE !separate(!POS !CMDEND)
PRESERVE.
SET PRINTBACK = ON MPRINT = ON.
!DO !s !IN (!1)
VECTOR !CONCAT(!s,"_group(6)").
RECODE
  !CONCAT(!s,"_group1 TO ",!s,"_group6) (ELSE=0).
COMPUTE !CONCAT(!s,"_group(V1)"= !s.
APPLY DICTIONARY FROM * /SOURCE VAR = !s/TARGET VAR = !CONCAT(!s,"_group1 TO ",!s,"_group6) .
DOEND
RESTORE.
!ENDDEFINE.

ORIGINAL FOR CONTEXT.

"DEFINE !separate(!POS !CMDEND)
PRESERVE.
SET PRINTBACK = ON MPRINT = ON.
!DO !s !IN (!1)
!DO !group = 1 !TO 6
!LET !new = !CONCAT(!s,"_group",!group)
IF (V1 = !group) !new = !s.
APPLY DICTIONARY FROM * /SOURCE VAR = !s/TARGET VAR = !new.
!DOEND
!DOEND
RESTORE.
!ENDDEFINE.

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

David Marso-2
In reply to this post by emma78
Thanks Mario, Good catch.
 Typing on my phone. Easy to misfire on details.
Spotted another one. Missing "quote" here.

!CONCAT(!s,"_group1 TO ",!s,"_group6)
Should be:
CONCAT(!s,"_group1 TO ",!s,"_group6")

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