Date: Thu, 21 Oct 2010 17:04:36 -0400
Reply-To: David Marso <david.marso@GMAIL.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: David Marso <david.marso@GMAIL.COM>
Subject: Re: LOOP - END LOOP
Your description might seem clear to you, but you really should post an
example of what the resulting data file needs to look like.
The following MIGHT be what you are after but YMMV.
data list free /varA varB varC varD.
begin data
1 1 0 1000
1 2 0 0
1 3 0 0
1 4 1 100
1 5 0 0
2 1 0 0
2 2 0 1500
2 3 2 200
end data.
COMPUTE link=varc.
AGGREGATE OUTFILE "C:\temp\junk.sav"
/BREAK vara
/link=max(link)
/vare=SUM(vard).
COMPUTE link=varb.
MATCH FILES
/ FILE *
/ FILE "C:\temp\junk.sav"
/ BY vara link.
FORMATS ALL (F4.0).
LIST.
VARA VARB VARC VARD LINK VARE
1 1 0 1000 1 1100
1 2 0 0 2 .
1 3 0 0 3 .
1 4 1 100 4 .
1 5 0 0 5 .
2 1 0 0 1 .
2 2 0 1500 2 1700
2 3 2 200 3 .
Number of cases read: 8 Number of cases listed: 8
On Wed, 20 Oct 2010 08:36:42 -0400, Shane S Allua <ssallua@us.ibm.com> wrote:
>
>Hello,
>I have the following data file:
>
>
>
>varA varB varC varD
>1 1 0 1000
>1 2 0 0
>1 3 0 0
>1 4 1 100
>1 5 0 0
>2 1 0 0
>2 2 0 1500
>2 3 2 200
>
>For each value of varB within varA, I need to add the values of varD only
>if varB=varC for any varB. So for varA = 1, I need to sum the values of
>varD where varB = 1 and varB=4 such that a new varE= 1000+100.
>
> For varA=2, I need to sum the values of varD for varB =2 and varB =3 such
>that varE= 1500+200. Essentially, for each varB within varA, I need SPSS
>to loop through each value of varC and when varB=varC for any varB , sum
>the values of varD.
>
>I have tried several iterations of LOOP - END LOOP but have only succeeded
>when for any ONE case, varB = varC.
>
>If any one has any recommendations, your assistance would be greatly
>appreciated.
>
>
>
>Thanks!
>
>Shane
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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
|