This is probably a hopeless case, but: Is there any way to run an aggregate command in conjunction
with IF or DO IF? Ie: SORT CASES BY IDNO INDIVNO. DO IF SOMEVAL > 3 compute XYZ = 1. ELSE. Compute XYZ = 0. END IF. if XYZ = 1 AGGREGATE /MODE=ADDVARIABLES /OVERWRITE=YES /BREAK=IDNO
INDIVNO Num_Filers=Sum(Filer). execute. Or is there some other command I’m not thinking of
that would do something similar to AGGREGATE that works with IF statements? I’m trying to do this because we are creating combined
syntax that must deal with multiple data conditions, and the alternative is to
do it in a very long, complex way. John
Krampner | Research Associate NYC
Center for Economic Opportunity / HRA Note new phone #: (929) 221-6560 |
Try using FILTER prior to AGGREGATE, as
in:
dataset close all. new file. data list free /a. begin data 1 2 3 4 5 end data. compute xyz= a>3. filter by xyz. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=a /N_BREAK=N. filter off. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: "Krampner, John" <[hidden email]> To: [hidden email], Date: 06/11/2013 04:07 PM Subject: any way to combine IF and AGGREGATE? Sent by: "SPSSX(r) Discussion" <[hidden email]> This is probably a hopeless case, but: Is there any way to run an aggregate command in conjunction with IF or DO IF? Ie: SORT CASES BY IDNO INDIVNO. DO IF SOMEVAL > 3 compute XYZ = 1. ELSE. Compute XYZ = 0. END IF. if XYZ = 1 AGGREGATE /MODE=ADDVARIABLES /OVERWRITE=YES /BREAK=IDNO INDIVNO Num_Filers=Sum(Filer). execute. Or is there some other command I’m not thinking of that would do something similar to AGGREGATE that works with IF statements? I’m trying to do this because we are creating combined syntax that must deal with multiple data conditions, and the alternative is to do it in a very long, complex way. John Krampner | Research Associate NYC Center for Economic Opportunity / HRA Note new phone #: (929) 221-6560 [hidden email] |
In reply to this post by Krampner, John
Oops. That doesn't work. It overwrites
the filtered aggregate values with sysmis.
Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: Rick Oliver/Chicago/IBM To: "Krampner, John" <[hidden email]>, Cc: [hidden email] Date: 06/11/2013 04:34 PM Subject: Re: any way to combine IF and AGGREGATE? Try using FILTER prior to AGGREGATE, as in: dataset close all. new file. data list free /a. begin data 1 2 3 4 5 end data. compute xyz= a>3. filter by xyz. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=a /N_BREAK=N. filter off. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: "Krampner, John" <[hidden email]> To: [hidden email], Date: 06/11/2013 04:07 PM Subject: any way to combine IF and AGGREGATE? Sent by: "SPSSX(r) Discussion" <[hidden email]> This is probably a hopeless case, but: Is there any way to run an aggregate command in conjunction with IF or DO IF? Ie: SORT CASES BY IDNO INDIVNO. DO IF SOMEVAL > 3 compute XYZ = 1. ELSE. Compute XYZ = 0. END IF. if XYZ = 1 AGGREGATE /MODE=ADDVARIABLES /OVERWRITE=YES /BREAK=IDNO INDIVNO Num_Filers=Sum(Filer). execute. Or is there some other command I’m not thinking of that would do something similar to AGGREGATE that works with IF statements? I’m trying to do this because we are creating combined syntax that must deal with multiple data conditions, and the alternative is to do it in a very long, complex way. John Krampner | Research Associate NYC Center for Economic Opportunity / HRA Note new phone #: (929) 221-6560 [hidden email] |
In reply to this post by Krampner, John
This should work:
dataset close all. new file. data list free /a. begin data 1 2 3 4 5 end data. dataset name one. compute aggvar=999. /*just to show we aren't overwriting unselected cases. dataset copy two. dataset activate two. select if a>3. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES /BREAK=a /aggvar=N. *merge files, order is important, file with new values must come first. match files file=* /file=one /by a. execute. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: Rick Oliver/Chicago/IBM To: Rick Oliver/Chicago/IBM@IBMUS, Cc: "Krampner, John" <[hidden email]>, [hidden email] Date: 06/11/2013 04:47 PM Subject: Re: any way to combine IF and AGGREGATE? Oops. That doesn't work. It overwrites the filtered aggregate values with sysmis. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: Rick Oliver/Chicago/IBM To: "Krampner, John" <[hidden email]>, Cc: [hidden email] Date: 06/11/2013 04:34 PM Subject: Re: any way to combine IF and AGGREGATE? Try using FILTER prior to AGGREGATE, as in: dataset close all. new file. data list free /a. begin data 1 2 3 4 5 end data. compute xyz= a>3. filter by xyz. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=a /N_BREAK=N. filter off. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: "Krampner, John" <[hidden email]> To: [hidden email], Date: 06/11/2013 04:07 PM Subject: any way to combine IF and AGGREGATE? Sent by: "SPSSX(r) Discussion" <[hidden email]> This is probably a hopeless case, but: Is there any way to run an aggregate command in conjunction with IF or DO IF? Ie: SORT CASES BY IDNO INDIVNO. DO IF SOMEVAL > 3 compute XYZ = 1. ELSE. Compute XYZ = 0. END IF. if XYZ = 1 AGGREGATE /MODE=ADDVARIABLES /OVERWRITE=YES /BREAK=IDNO INDIVNO Num_Filers=Sum(Filer). execute. Or is there some other command I’m not thinking of that would do something similar to AGGREGATE that works with IF statements? I’m trying to do this because we are creating combined syntax that must deal with multiple data conditions, and the alternative is to do it in a very long, complex way. John Krampner | Research Associate NYC Center for Economic Opportunity / HRA Note new phone #: (929) 221-6560 [hidden email] |
In reply to this post by Krampner, John
At 05:05 PM 6/11/2013, Krampner, John wrote:
>Is there any way to run an aggregate command in conjunction with IF or DO IF? >Ie: > >SORT CASES BY IDNO INDIVNO. >DO IF SOMEVAL > 3 >compute XYZ = 1. >ELSE. > Compute XYZ = 0. >END IF. >if XYZ = 1 AGGREGATE > /MODE=ADDVARIABLES /OVERWRITE=YES > /BREAK=IDNO INDIVNO > Num_Filers=Sum(Filer). IF absolutely won't govern AGGREGATE; it goes within a transformation program only, and AGGREGATE is a procedure. (*) The usual way is to use IF to compute a variable which has only those values you want included in the aggregation. Something like this, though I'm a little rusty and I haven't tested this: SORT CASES BY IDNO INDIVNO. DO IF SOMEVAL > 3 . compute XYZ = 1. ELSE. . Compute XYZ = 0. END IF. if XYZ = 1 Num_Filers = Filer. AGGREGATE /MODE=ADDVARIABLES /OVERWRITE=YES /BREAK=IDNO INDIVNO Num_Filers=Sum(Num_Filer). ===================== 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 |
Banned User
|
I will be out of the office until Monday, June 17, 2013, with limited access to email. However, please know that your message
is very important to me and I will respond when I return. Thank you. If this is an emergency, please call our office at 734.459.1030.
Thank you.
Sincerely,
Cheryl _____________________________________________________
Cheryl A. Boglarsky, Ph.D. Human Synergistics, Inc.
39819 Plymouth Road
Plymouth, MI 48170
734.459.1030
This message includes legally privileged and confidential information that is intended only for the use of the recipient named above. All readers
of this message, other than the intended recipient, are hereby notified that any dissemination, modification, distribution or reproduction of this e-mail is strictly forbidden.
|
In reply to this post by Krampner, John
Hi John,
Have you tried 'temporary' commands? We use something like this to break apart service files by month and save the aggregates, but I think it should work for adding variables . DATA LIST LIST / VARA (F5.0) VARB (A1). BEGIN DATA 1 a 2 b 3 c 4 d 5 d 6 d 7 d 8 e 9 e 10 e. END DATA. temporary. select if VARA ge 4. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=VARB /VARA_sum = SUM(VARA). execute. - Emma ________________________________________ From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Krampner, John [[hidden email]] Sent: Tuesday, June 11, 2013 5:05 PM To: [hidden email] Subject: any way to combine IF and AGGREGATE? This is probably a hopeless case, but: Is there any way to run an aggregate command in conjunction with IF or DO IF? Ie: SORT CASES BY IDNO INDIVNO. DO IF SOMEVAL > 3 compute XYZ = 1. ELSE. Compute XYZ = 0. END IF. if XYZ = 1 AGGREGATE /MODE=ADDVARIABLES /OVERWRITE=YES /BREAK=IDNO INDIVNO Num_Filers=Sum(Filer). execute. Or is there some other command I’m not thinking of that would do something similar to AGGREGATE that works with IF statements? I’m trying to do this because we are creating combined syntax that must deal with multiple data conditions, and the alternative is to do it in a very long, complex way. John Krampner | Research Associate NYC Center for Economic Opportunity / HRA Note new phone #: (929) 221-6560 [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 |
Free forum by Nabble | Edit this page |