Looping

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

Looping

jenmabrey
I am trying to loop the syntax below (I inserted "LOOP" and "END LOOP"
where I need them), but get many error messages trying to run the
syntax.  I don't really have any experience with the loop function, so
could someone please offer a recommendation on how to get the syntax to
loop or repeat?  Do I need a combination of Loop, Repeat, Vector?  Any
help would be greatly appreciated.

 

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

EXECUTE.

 

LOOP #I = 1 to 3.

 

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

-SAVE OUTFILE='C:\Documents and
Settings\jlmabrey\Desktop\respdataTEST.sav'.

-DO IF (#I=1).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13  & (q5=1 | q5=2)).

-COMPUTE CELL_ID=1.

-ELSE IF (#I=2).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13 & Age<=16 & (q5=1 | q5=2))

-COMPUTE CELL_ID=2.

-ELSE IF (#I=3).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=16 & Age<=24 & (q5=1 | q5=2))

-COMPUTE CELL_ID=3.

-END IF.

-SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breakraw.sav'.

-COMPUTE N=1.

AGGREGATE

 /OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'

 /BREAK= CELL_ID

 /Base=sum(N)

 /Top2_1count=sum(Top2_1count)

 /Top2_2count=sum(top2_2count)

 /Top2_3count=sum(top2_3count)

 /Top2_4count=sum(Top2_4count)

 /Top2_5count=sum(Top2_5count)

 /Top2_6count=sum(Top2_6count)

 /Top2_7count=sum(Top2_7count)

 /Top2_8count=sum(Top2_8count)

 /Top2_9count=sum(Top2_9count)

 /Top2_10count=sum(Top2_10count)

 /Top2_11count=sum(Top2_11count)

 /Top2_12count=sum(Top2_12count)

 /Top2_13count=sum(Top2_13count)

 /Top2_14count=sum(Top2_14count)

 /Top2_15count=sum(top2_15count)

 /Top2_16count=sum(top2_16count)

 /Top2_17count=sum(top2_17count)

 /Top2_18count=sum(top2_18count)

 /Top2_19count=sum(top2_19count).

 

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

MATCH FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\variouscalcs.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.

ADD FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.

 

END LOOP.

 

 

 
This email message is intended for use only by the person(s) or entity to which it is addressed and may contain privileged or confidential information owned by rsc THE QUALITY MEASUREMENT COMPANY. Any unauthorized use or disclosure of this information is strictly prohibited. Copyright 2008 rsc. All rights reserved

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

Melissa Ives
It would be helpful to specify what you are trying to do with the loop and what errors you are getting.  The list can be more helpful if we all know what you have and where you want to go.

However, to start if this is your exact syntax, the GET and SAVE file commands cannot be within the loop.
Do those before/after the LOOP/END LOOP.  Also it appears that you have loops and conditional select statements that you are trying to turn off with a 'filter off'.  Using a select if statement is not the same as using a filter, SELECT drops the unselected cases from the active dataset while filter marks them as not used in the analyses.  So using SELECT, by the time you get to '-SELECT IF(Age>=16 & Age<=24 & (q5=1 | q5=2))' there are no cases left since they were deselected in the first.

When I run into syntax I'm not sure about, I use the SPSS built in help to be sure a) it does what I want and b) I have it set up correctly.

HTH,
Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mabrey, Jennifer L.
Sent: Monday, August 18, 2008 10:40 AM
To: [hidden email]
Subject: [SPSSX-L] Looping

I am trying to loop the syntax below (I inserted "LOOP" and "END LOOP"
where I need them), but get many error messages trying to run the syntax.  I don't really have any experience with the loop function, so could someone please offer a recommendation on how to get the syntax to loop or repeat?  Do I need a combination of Loop, Repeat, Vector?  Any help would be greatly appreciated.



GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

EXECUTE.

LOOP #I = 1 to 3.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

-SAVE OUTFILE='C:\Documents and
Settings\jlmabrey\Desktop\respdataTEST.sav'.

-DO IF (#I=1).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13  & (q5=1 | q5=2)).

-COMPUTE CELL_ID=1.

-ELSE IF (#I=2).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13 & Age<=16 & (q5=1 | q5=2))

-COMPUTE CELL_ID=2.

-ELSE IF (#I=3).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=16 & Age<=24 & (q5=1 | q5=2))

-COMPUTE CELL_ID=3.

-END IF.

-SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breakraw.sav'.

-COMPUTE N=1.

AGGREGATE

 /OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'

 /BREAK= CELL_ID

 /Base=sum(N)

 /Top2_1count=sum(Top2_1count)

 /Top2_2count=sum(top2_2count)

 /Top2_3count=sum(top2_3count)

 /Top2_4count=sum(Top2_4count)

 /Top2_5count=sum(Top2_5count)

 /Top2_6count=sum(Top2_6count)

 /Top2_7count=sum(Top2_7count)

 /Top2_8count=sum(Top2_8count)

 /Top2_9count=sum(Top2_9count)

 /Top2_10count=sum(Top2_10count)

 /Top2_11count=sum(Top2_11count)

 /Top2_12count=sum(Top2_12count)

 /Top2_13count=sum(Top2_13count)

 /Top2_14count=sum(Top2_14count)

 /Top2_15count=sum(top2_15count)

 /Top2_16count=sum(top2_16count)

 /Top2_17count=sum(top2_17count)

 /Top2_18count=sum(top2_18count)

 /Top2_19count=sum(top2_19count).



GET FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

MATCH FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\variouscalcs.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.

ADD FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.



END LOOP.






This email message is intended for use only by the person(s) or entity to which it is addressed and may contain privileged or confidential information owned by rsc THE QUALITY MEASUREMENT COMPANY. Any unauthorized use or disclosure of this information is strictly prohibited. Copyright 2008 rsc. All rights reserved

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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

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

jenmabrey
I'm trying to create a new file with summarized data based on different
filter criteria from rawdatatest.sav.  I would like it to go back and
loop until it gets through all of my selection criteria so I can lump
the case selections into one section.  The reason I'm starting with the
raw data and saving each time is because of the "select cases" deleting
my unused cases.  I'm also adding variables/data from the
variouscalcs.sav file that I'm calling later in the loop.  I could add
"variouscalcs.sav" after the loop, but it always includes just one case
and I need that data added to each case in my new file.  The data in the
variouscalcs.sav file will be identical for each case in my newly
created final.sav file.

Most of my error messages to refer to not being able to save a file but
the error is not real clear about why and the built in help has not been
useful.  Any suggestions are helpful and appreciated.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Melissa Ives
Sent: Monday, August 18, 2008 11:02 AM
To: [hidden email]
Subject: Re: Looping

It would be helpful to specify what you are trying to do with the loop
and what errors you are getting.  The list can be more helpful if we all
know what you have and where you want to go.

However, to start if this is your exact syntax, the GET and SAVE file
commands cannot be within the loop.
Do those before/after the LOOP/END LOOP.  Also it appears that you have
loops and conditional select statements that you are trying to turn off
with a 'filter off'.  Using a select if statement is not the same as
using a filter, SELECT drops the unselected cases from the active
dataset while filter marks them as not used in the analyses.  So using
SELECT, by the time you get to '-SELECT IF(Age>=16 & Age<=24 & (q5=1 |
q5=2))' there are no cases left since they were deselected in the first.

When I run into syntax I'm not sure about, I use the SPSS built in help
to be sure a) it does what I want and b) I have it set up correctly.

HTH,
Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Mabrey, Jennifer L.
Sent: Monday, August 18, 2008 10:40 AM
To: [hidden email]
Subject: [SPSSX-L] Looping

I am trying to loop the syntax below (I inserted "LOOP" and "END LOOP"
where I need them), but get many error messages trying to run the
syntax.  I don't really have any experience with the loop function, so
could someone please offer a recommendation on how to get the syntax to
loop or repeat?  Do I need a combination of Loop, Repeat, Vector?  Any
help would be greatly appreciated.



GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

EXECUTE.

LOOP #I = 1 to 3.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

-SAVE OUTFILE='C:\Documents and
Settings\jlmabrey\Desktop\respdataTEST.sav'.

-DO IF (#I=1).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13  & (q5=1 | q5=2)).

-COMPUTE CELL_ID=1.

-ELSE IF (#I=2).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13 & Age<=16 & (q5=1 | q5=2))

-COMPUTE CELL_ID=2.

-ELSE IF (#I=3).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=16 & Age<=24 & (q5=1 | q5=2))

-COMPUTE CELL_ID=3.

-END IF.

-SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breakraw.sav'.

-COMPUTE N=1.

AGGREGATE

 /OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'

 /BREAK= CELL_ID

 /Base=sum(N)

 /Top2_1count=sum(Top2_1count)

 /Top2_2count=sum(top2_2count)

 /Top2_3count=sum(top2_3count)

 /Top2_4count=sum(Top2_4count)

 /Top2_5count=sum(Top2_5count)

 /Top2_6count=sum(Top2_6count)

 /Top2_7count=sum(Top2_7count)

 /Top2_8count=sum(Top2_8count)

 /Top2_9count=sum(Top2_9count)

 /Top2_10count=sum(Top2_10count)

 /Top2_11count=sum(Top2_11count)

 /Top2_12count=sum(Top2_12count)

 /Top2_13count=sum(Top2_13count)

 /Top2_14count=sum(Top2_14count)

 /Top2_15count=sum(top2_15count)

 /Top2_16count=sum(top2_16count)

 /Top2_17count=sum(top2_17count)

 /Top2_18count=sum(top2_18count)

 /Top2_19count=sum(top2_19count).



GET FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

MATCH FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\variouscalcs.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.

ADD FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.



END LOOP.






This email message is intended for use only by the person(s) or entity
to which it is addressed and may contain privileged or confidential
information owned by rsc THE QUALITY MEASUREMENT COMPANY. Any
unauthorized use or disclosure of this information is strictly
prohibited. Copyright 2008 rsc. All rights reserved

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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

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

Melissa Ives
You want to calculate CELL_ID and then use it to aggregate the Top..count variables, then merge in the variouscalcs data.

I think I see a couple of options:
To create CELL_ID you could just use this.
IF(Age>=13  & (q5=1 | q5=2)) CELL_ID=1. <--did you mean to say "Less than" 13 instead of "Greater than or equal to"?
IF(Age>=13 & Age<=16 & (q5=1 | q5=2)) CELL_ID=2.
IF(Age>=16 & Age<=24 & (q5=1 | q5=2)) CELL_ID=3. <--the way this is written, all 16y.o. will end up in this group.  One of these should not include the '=' sign.

What should happen to those cases where q5 is not 1 or 2?

Alternatively, you may want to do-this will leave q5>2 or <1 as system missing:
Do if (q5=1 | q5=2).
  Recode age (lo thru 12=1) (13 thru 16=2) (17 thru 24=3) into CELL_ID.
End if.

Then you can run your aggregate command (you may want to review the addvariables subcommand to see if you want to use it.

It sounds like variouscalcs.sav is a single record that needs to be matched onto each row in the breaksum file (or the rawdata with the breaksum variables added if you chose to use that feature of the AGGREGATE COMMAND.
To do this change the syntax to identify variouscalcs as a lookup table:
MATCH FILES /FILE=*/TABLE='C:\Documents and Settings\jlmabrey\Desktop\variouscalcs.sav'.
                          ^^^^^
Using the ADD FILES command would result in the final file (where did that come from as it wasn't created earlier in this syntax?) and the updated breaksum file.

Final1
Final2
Final3 (etc.)
        breaksum1
        breaksum2
        breaksum3(etc.)

Do you want that or are you looking for:?
Final1 breaksum1
Final2 breaksum2
Final3 breaksum3 (etc.)

Melissa

-----Original Message-----
From: Mabrey, Jennifer L. [mailto:[hidden email]]
Sent: Monday, August 18, 2008 1:44 PM
To: Melissa Ives; [hidden email]
Subject: RE: Re: Looping

I'm trying to create a new file with summarized data based on different filter criteria from rawdatatest.sav.  I would like it to go back and loop until it gets through all of my selection criteria so I can lump the case selections into one section.  The reason I'm starting with the raw data and saving each time is because of the "select cases" deleting my unused cases.  I'm also adding variables/data from the variouscalcs.sav file that I'm calling later in the loop.  I could add "variouscalcs.sav" after the loop, but it always includes just one case and I need that data added to each case in my new file.  The data in the variouscalcs.sav file will be identical for each case in my newly created final.sav file.

Most of my error messages to refer to not being able to save a file but the error is not real clear about why and the built in help has not been useful.  Any suggestions are helpful and appreciated.
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Melissa Ives
Sent: Monday, August 18, 2008 11:02 AM
To: [hidden email]
Subject: Re: Looping

It would be helpful to specify what you are trying to do with the loop and what errors you are getting.  The list can be more helpful if we all know what you have and where you want to go.

However, to start if this is your exact syntax, the GET and SAVE file commands cannot be within the loop.
Do those before/after the LOOP/END LOOP.  Also it appears that you have loops and conditional select statements that you are trying to turn off with a 'filter off'.  Using a select if statement is not the same as using a filter, SELECT drops the unselected cases from the active dataset while filter marks them as not used in the analyses.  So using SELECT, by the time you get to '-SELECT IF(Age>=16 & Age<=24 & (q5=1 | q5=2))' there are no cases left since they were deselected in the first.

When I run into syntax I'm not sure about, I use the SPSS built in help to be sure a) it does what I want and b) I have it set up correctly.

HTH,
Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mabrey, Jennifer L.
Sent: Monday, August 18, 2008 10:40 AM
To: [hidden email]
Subject: [SPSSX-L] Looping

I am trying to loop the syntax below (I inserted "LOOP" and "END LOOP"
where I need them), but get many error messages trying to run the syntax.  I don't really have any experience with the loop function, so could someone please offer a recommendation on how to get the syntax to loop or repeat?  Do I need a combination of Loop, Repeat, Vector?  Any help would be greatly appreciated.



GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

EXECUTE.

LOOP #I = 1 to 3.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

-SAVE OUTFILE='C:\Documents and
Settings\jlmabrey\Desktop\respdataTEST.sav'.

-DO IF (#I=1).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13  & (q5=1 | q5=2)).

-COMPUTE CELL_ID=1.

-ELSE IF (#I=2).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=13 & Age<=16 & (q5=1 | q5=2))

-COMPUTE CELL_ID=2.

-ELSE IF (#I=3).

-FILTER OFF.

-USE ALL.

-SELECT IF(Age>=16 & Age<=24 & (q5=1 | q5=2))

-COMPUTE CELL_ID=3.

-END IF.

-SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breakraw.sav'.

-COMPUTE N=1.

AGGREGATE

 /OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'

 /BREAK= CELL_ID

 /Base=sum(N)

 /Top2_1count=sum(Top2_1count)

 /Top2_2count=sum(top2_2count)

 /Top2_3count=sum(top2_3count)

 /Top2_4count=sum(Top2_4count)

 /Top2_5count=sum(Top2_5count)

 /Top2_6count=sum(Top2_6count)

 /Top2_7count=sum(Top2_7count)

 /Top2_8count=sum(Top2_8count)

 /Top2_9count=sum(Top2_9count)

 /Top2_10count=sum(Top2_10count)

 /Top2_11count=sum(Top2_11count)

 /Top2_12count=sum(Top2_12count)

 /Top2_13count=sum(Top2_13count)

 /Top2_14count=sum(Top2_14count)

 /Top2_15count=sum(top2_15count)

 /Top2_16count=sum(top2_16count)

 /Top2_17count=sum(top2_17count)

 /Top2_18count=sum(top2_18count)

 /Top2_19count=sum(top2_19count).



GET FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

MATCH FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\variouscalcs.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.

ADD FILES /FILE=*

/FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.



END LOOP.






This email message is intended for use only by the person(s) or entity to which it is addressed and may contain privileged or confidential information owned by rsc THE QUALITY MEASUREMENT COMPANY. Any unauthorized use or disclosure of this information is strictly prohibited. Copyright 2008 rsc. All rights reserved

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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance.

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

Richard Ristow
In reply to this post by jenmabrey
Part I:  LOOP and AGGREGATE

At 11:40 AM 8/18/2008, Mabrey, Jennifer L. wrote:

>I am trying to loop this syntax below (I inserted "LOOP" and "END
>LOOP" where I need them), but get many error messages trying to run the syntax.

As Melissa Ives said, LOOP/END LOOP is part of the transformation
language. It only works within a transformation program or INPUT
PROGRAM (and then, only within the processing of a single case at a
time); it can't loop any command that ends a transformation program
or begins a new one. (Such commands include GET FILE, DATA LIST, etc;
SAVE; and all procedures, including EXECUTE.)

You can loop over all commands with a macro loop or a Python loop.
But it doesn't look like that's what you want, for setting your cell IDs.

Try something like this (not tested). (There are complications if
'Age' or 'q5' are ever missing; and your logic doesn't seem to
guarantee that every case will get a non-missing CELL_ID.)

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\rawdataTEST.sav'.

DO IF   (Age>=13  & (q5=1 | q5=2)).
-  COMPUTE CELL_ID=1.
ELSE IF (Age>=13 & Age<=16 & (q5=1 | q5=2)).
-  COMPUTE CELL_ID=2.
ELSE IF (Age>=16 & Age<=24 & (q5=1 | q5=2)).
-  COMPUTE CELL_ID=3.
END IF.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breakraw.sav'.


Then, your AGGREGATE logic should work. If you like, you can simplify

COMPUTE N=1.
AGGREGATE
  /OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'
  /BREAK= CELL_ID
  /Base=sum(N)
[etc.]

to
AGGREGATE
  /OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'
  /BREAK= CELL_ID
  /Base=N
[etc.]

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

Richard Ristow
In reply to this post by jenmabrey
Part II: Adding cases and variables

At 02:43 PM 8/18/2008, Mabrey, Jennifer L. wrote:

>I'm also adding variables/data from the variouscalcs.sav file that
>I'm calling later in the loop.  I could add "variouscalcs.sav" after
>the loop, but it always includes just one case and I need that data
>added to each case in my new file.  The data in the variouscalcs.sav
>file will be identical for each case in my newly
>created final.sav file.

That means, there's only one case in "variouscalcs.sav"; or, there
are multiple cases, but they all have the same data? If that's what
you do mean, the following (untested) should work:

*  Take one case from "variouscalcs.sav", and add variable NOBREAK:.

GET
  FILE='C:\Documents and Settings\jlmabrey\Desktop\variouscalcs.sav'.

RECODE $CASENUM (1 = 1) (ELSE= 0) INTO NOBREAK.
SELECT IF NOBREAK = 1.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\OneCalc.sav'.


*  Add NOBREAK to the aggregated file created in Part I:.

GET FILE='C:\Documents and Settings\jlmabrey\Desktop\breaksum.sav'.
COMPUTE NOBREAK = 1.

*  and join with the (single record) of calculations.  .
*  (The key technique is "/TABLE=" on MATCH FILES.)    .

MATCH FILES /FILE=*
  /TABLE='C:\Documents and Settings\jlmabrey\Desktop\OneCalc.sav'
  /BY NOBREAK.

SAVE OUTFILE='C:\Documents and Settings\jlmabrey\Desktop\final.sav'.

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