All,
Can someone please give me an example of the use of ANY within the select if command? I have a list of difference variables and I want to select cases where the difference is not zero. TIA, Tony A. J. Baglioni, jr. Assistant Professor McIntire School of Commerce University of Virginia 434 924-4961 |
I believe you could achieve that without using the ANY!
e.g. Select if var ne 0. exe. where ne = not equal to. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Baglioni, Tony Sent: Monday, September 11, 2006 10:31 AM To: [hidden email] Subject: using ANY in select if All, Can someone please give me an example of the use of ANY within the select if command? I have a list of difference variables and I want to select cases where the difference is not zero. TIA, Tony A. J. Baglioni, jr. Assistant Professor McIntire School of Commerce University of Virginia 434 924-4961 |
In reply to this post by Baglioni, Tony
All,
Can someone please give me an example of the use of ANY within the select if command? I have a list of difference variables and I want to select cases where the difference is not zero. Let me clarify. I want to avoid saying SELECT IF (var1 ne 0 or var2 ne 0 or var3 ne 0 ... or var22 ne 0). Hope this clarifies. TIA, Tony A. J. Baglioni, jr. Assistant Professor McIntire School of Commerce University of Virginia 434 924-4961 |
In reply to this post by Baglioni, Tony
Hi Tony,
You wish to select cases where at least one of the difference variables is not zero? Try e.g. this: Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. Is this what you need? Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Baglioni, Tony Sent: Monday, September 11, 2006 4:31 PM To: [hidden email] Subject: using ANY in select if All, Can someone please give me an example of the use of ANY within the select if command? I have a list of difference variables and I want to select cases where the difference is not zero. TIA, Tony A. J. Baglioni, jr. Assistant Professor McIntire School of Commerce University of Virginia 434 924-4961 |
The reason why Jan proposes this in place of select if not(any(0, v1, v2, v3, v4...) is probably because max and min honor the "to" convention to name a set of contiguous variables. If they are not contiguous, then the ANY function is probably simpler to use.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Spousta Jan Sent: Monday, September 11, 2006 9:44 AM To: [hidden email] Subject: Re: using ANY in select if Hi Tony, You wish to select cases where at least one of the difference variables is not zero? Try e.g. this: Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. Is this what you need? Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Baglioni, Tony Sent: Monday, September 11, 2006 4:31 PM To: [hidden email] Subject: using ANY in select if All, Can someone please give me an example of the use of ANY within the select if command? I have a list of difference variables and I want to select cases where the difference is not zero. TIA, Tony A. J. Baglioni, jr. Assistant Professor McIntire School of Commerce University of Virginia 434 924-4961 |
In reply to this post by Baglioni, Tony
At 10:38 AM 9/11/2006, Baglioni, Tony wrote:
>Can someone please give me an example of the use of ANY within the >select if command? I have a list of difference variables and I want >to select cases where the difference is not zero. Let me clarify. I >want to avoid saying > >SELECT IF (var1 ne 0 or var2 ne 0 or var3 ne 0 ... or var22 ne 0). ANY isn't well suited, as you've noticed: It does an 'or' of a set of equality comparisons; you want an 'or' of a set of inequality comparisons (any value is not zero). Jan Spousta's is a very good 'cute' solution - 'cute', meaning that it does the job nicely, but in a way that wouldn't strike one immediately from the requirement. I'd probably use it. You can at least write the direct logic more easily with a DO REPEAT. Untested: COMPUTE #TAKE_IT = 0. DO REPEAT TEST_VAL = var1 TO var22. . IF (TEST_VAL NE 0) #TAKE_IT = 1. END REPEAT. SELECT IF #TAKE_IT EQ 1. |
In reply to this post by Baglioni, Tony
I hope that it is still possible to write
select if not(any(0, v1 to v10)). The problem is that this gives a different logic - it selects cases where there is no zero in v1 to v10. While my solution selects those cases where at least one variable is non-zero. It is how I understand Tony's posting. Greetings Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Beadle, ViAnn Sent: Monday, September 11, 2006 5:13 PM To: [hidden email] Subject: Re: using ANY in select if The reason why Jan proposes this in place of select if not(any(0, v1, v2, v3, v4...) is probably because max and min honor the "to" convention to name a set of contiguous variables. If they are not contiguous, then the ANY function is probably simpler to use. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Spousta Jan Sent: Monday, September 11, 2006 9:44 AM To: [hidden email] Subject: Re: using ANY in select if Hi Tony, You wish to select cases where at least one of the difference variables is not zero? Try e.g. this: Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. Is this what you need? Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Baglioni, Tony Sent: Monday, September 11, 2006 4:31 PM To: [hidden email] Subject: using ANY in select if All, Can someone please give me an example of the use of ANY within the select if command? I have a list of difference variables and I want to select cases where the difference is not zero. TIA, Tony A. J. Baglioni, jr. Assistant Professor McIntire School of Commerce University of Virginia 434 924-4961 |
>
>-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of >Spousta Jan >Sent: Monday, September 11, 2006 9:44 AM >To: [hidden email] >Subject: Re: using ANY in select if > >Hi Tony, > >You wish to select cases where at least one of the difference variables >is not zero? Try e.g. this: > >Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. > >Is this what you need? > >Jan If Jan's interpretation of the original question is right, you could also add up the absolute value of each difference, using a SUM function, and Select If SUM > 0 Bob Schacht >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of >Baglioni, Tony >Sent: Monday, September 11, 2006 4:31 PM >To: [hidden email] >Subject: using ANY in select if > >All, > > > >Can someone please give me an example of the use of ANY within the >select if command? I have a list of difference variables and I want to >select cases where the difference is not zero. > > > >TIA, > >Tony > > > >A. J. Baglioni, jr. > >Assistant Professor > >McIntire School of Commerce > >University of Virginia > >434 924-4961 Robert M. Schacht, Ph.D., Research Director Pacific Basin Research and Training Center 1268 Young Street, Suite #204 Research Center, University of Hawaii Honolulu, HI 96814 E-mail <[hidden email]> Phone 808-592-5904, FAX 808-592-5909 |
In reply to this post by Baglioni, Tony
This is not so easy, Bob, because ABS function does not support the cute
TO convention - you cannot write If sum(abs(v1 to v10)) > 0 /* WRONG COMMAND !!! */. So you must write If sum(abs(v1), abs(v2), etc.) > 0 Or use a loop as Richard Ristow devised earlier :-( Greetings Jan >If Jan's interpretation of the original question is right, you could also add up the absolute value of each > difference, using a SUM function, and Select If SUM > 0 > >Bob Schacht -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bob Schacht Sent: Tuesday, September 12, 2006 9:44 AM To: [hidden email] Subject: Re: using ANY in select if > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >Of Spousta Jan >Sent: Monday, September 11, 2006 9:44 AM >To: [hidden email] >Subject: Re: using ANY in select if > >Hi Tony, > >You wish to select cases where at least one of the difference variables >is not zero? Try e.g. this: > >Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. > >Is this what you need? > >Jan >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >Of Baglioni, Tony >Sent: Monday, September 11, 2006 4:31 PM >To: [hidden email] >Subject: using ANY in select if > >All, > > > >Can someone please give me an example of the use of ANY within the >select if command? I have a list of difference variables and I want to >select cases where the difference is not zero. > > > >TIA, > >Tony > > > >A. J. Baglioni, jr. > >Assistant Professor > >McIntire School of Commerce > >University of Virginia > >434 924-4961 Robert M. Schacht, Ph.D., Research Director Pacific Basin Research and Training Center 1268 Young Street, Suite #204 Research Center, University of Hawaii Honolulu, HI 96814 E-mail <[hidden email]> Phone 808-592-5904, FAX 808-592-5909 |
At 04:44 AM 9/12/2006, Spousta Jan wrote:
>This is not so easy, Bob, because ABS function does not support the >cute >TO convention - you cannot write > >If sum(abs(v1 to v10)) > 0 /* WRONG COMMAND !!! */. The problem, of course, isn't ABS. Any function that supported the TO convention would return, not a number, but a vector of numbers, as a single object. (This is NOT the same as the SPSS VECTOR of multiple objects - variables, or scratch variables.) It would be an interesting and profound extension to the datatypes supported in the transformation language. It would also be something you'd have to be careful with, since variable values would still probably have to be scalars; MY_VAR = abs(v1 to v10). couldn't work. Vector-valued scratch variables might: ##MY_VAR = abs(v1 to v10). but, again, this would be a profound extension. Now, "sum(abs(v1 to v10))" MIGHT be made to work with a less profound extension: the vector is needed only as an argument to "SUM", which returns a scalar. It would be useful for a lot of purposes, including this one. In fact, allowing a general expression instead of "ABS" would be even more useful. Even this would be a pretty profound extension, though not requiring full support for vector data objects. I'll be it doesn't make the SPSS priority list soon; indeed, unlike many of my other 'cute' ideas, I don't think I'd put it there. >So you must write > >If sum(abs(v1), abs(v2), etc.) > 0 > >Or use a loop as Richard Ristow devised earlier :-( > >Greetings > >Jan > > >If Jan's interpretation of the original question is right, you could >also add up the absolute value of each > > difference, using a SUM function, and Select If SUM > 0 > > > >Bob Schacht > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >Of >Bob Schacht >Sent: Tuesday, September 12, 2006 9:44 AM >To: [hidden email] >Subject: Re: using ANY in select if > > > > >-----Original Message----- > >From: SPSSX(r) Discussion [mailto:[hidden email]] On > Behalf > >Of Spousta Jan > >Sent: Monday, September 11, 2006 9:44 AM > >To: [hidden email] > >Subject: Re: using ANY in select if > > > >Hi Tony, > > > >You wish to select cases where at least one of the difference > variables > > >is not zero? Try e.g. this: > > > >Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. > > > >Is this what you need? > > > >Jan > > >-----Original Message----- > >From: SPSSX(r) Discussion [mailto:[hidden email]] On > Behalf > >Of Baglioni, Tony > >Sent: Monday, September 11, 2006 4:31 PM > >To: [hidden email] > >Subject: using ANY in select if > > > >All, > > > > > > > >Can someone please give me an example of the use of ANY within the > >select if command? I have a list of difference variables and I want > to > > >select cases where the difference is not zero. > > > > > > > >TIA, > > > >Tony > > > > > > > >A. J. Baglioni, jr. > > > >Assistant Professor > > > >McIntire School of Commerce > > > >University of Virginia > > > >434 924-4961 > >Robert M. Schacht, Ph.D., Research Director Pacific Basin Research and >Training Center >1268 Young Street, Suite #204 >Research Center, University of Hawaii >Honolulu, HI 96814 >E-mail <[hidden email]> >Phone 808-592-5904, FAX 808-592-5909 |
Well, as it happens, by taking advantage of programmability features in SPSS 15, vector-valued functions are easy to create. Initially the module for this, named trans, is part of the Bonus Pack for early adopters of SPSS 15, but it will be generally available on Developer Central after the Directions conference in early November.
Here is an example of a trivial program you could write that takes advantage of this. In the program below, the Python function vectorroot is defined as returning a list of square roots of each of the variables it is called with. EducToPrevexp is equivalent to educ TO prevexp The key part is the t.append line. This applies the function vectorroot to each variable in that list and creates new numeric variables with names like sqrt_educ. The t.execute line actually passes the data. (Yes, Richard, you do need this form of execute here :-)) begin program. import spssaux, trans, spss, math spssaux.OpenDataFile("c:/spss15/employee data.sav") def vectorroot(*vars): return [math.sqrt(v) for v in vars] d = spssaux.VariableDict() EducToPrevexp = d.range('educ', 'prevexp') numvars = len(EducToPrevexp) t = trans.Tfunction() t.append(vectorroot, ['sqrt_'+v for v in EducToPrevexp], numvars*['f'], EducToPrevexp) t.execute() end program. The Bonus Pack includes both the trans module and a collection of useful, nontrivial functions such as a soundex function that can be applied this way. Regards, Jon Peck SPSS -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow Sent: Tuesday, September 19, 2006 8:33 AM To: [hidden email] Subject: Re: [SPSSX-L] using ANY in select if At 04:44 AM 9/12/2006, Spousta Jan wrote: >This is not so easy, Bob, because ABS function does not support the >cute >TO convention - you cannot write > >If sum(abs(v1 to v10)) > 0 /* WRONG COMMAND !!! */. The problem, of course, isn't ABS. Any function that supported the TO convention would return, not a number, but a vector of numbers, as a single object. (This is NOT the same as the SPSS VECTOR of multiple objects - variables, or scratch variables.) It would be an interesting and profound extension to the datatypes supported in the transformation language. It would also be something you'd have to be careful with, since variable values would still probably have to be scalars; MY_VAR = abs(v1 to v10). couldn't work. Vector-valued scratch variables might: ##MY_VAR = abs(v1 to v10). but, again, this would be a profound extension. Now, "sum(abs(v1 to v10))" MIGHT be made to work with a less profound extension: the vector is needed only as an argument to "SUM", which returns a scalar. It would be useful for a lot of purposes, including this one. In fact, allowing a general expression instead of "ABS" would be even more useful. Even this would be a pretty profound extension, though not requiring full support for vector data objects. I'll be it doesn't make the SPSS priority list soon; indeed, unlike many of my other 'cute' ideas, I don't think I'd put it there. >So you must write > >If sum(abs(v1), abs(v2), etc.) > 0 > >Or use a loop as Richard Ristow devised earlier :-( > >Greetings > >Jan > > >If Jan's interpretation of the original question is right, you could >also add up the absolute value of each > > difference, using a SUM function, and Select If SUM > 0 > > > >Bob Schacht > >-----Original Message----- >From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf >Of >Bob Schacht >Sent: Tuesday, September 12, 2006 9:44 AM >To: [hidden email] >Subject: Re: using ANY in select if > > > > >-----Original Message----- > >From: SPSSX(r) Discussion [mailto:[hidden email]] On > Behalf > >Of Spousta Jan > >Sent: Monday, September 11, 2006 9:44 AM > >To: [hidden email] > >Subject: Re: using ANY in select if > > > >Hi Tony, > > > >You wish to select cases where at least one of the difference > variables > > >is not zero? Try e.g. this: > > > >Select if max(dif1 to dif10) > 0 or min(dif1 to dif10) < 0. > > > >Is this what you need? > > > >Jan > > >-----Original Message----- > >From: SPSSX(r) Discussion [mailto:[hidden email]] On > Behalf > >Of Baglioni, Tony > >Sent: Monday, September 11, 2006 4:31 PM > >To: [hidden email] > >Subject: using ANY in select if > > > >All, > > > > > > > >Can someone please give me an example of the use of ANY within the > >select if command? I have a list of difference variables and I want > to > > >select cases where the difference is not zero. > > > > > > > >TIA, > > > >Tony > > > > > > > >A. J. Baglioni, jr. > > > >Assistant Professor > > > >McIntire School of Commerce > > > >University of Virginia > > > >434 924-4961 > >Robert M. Schacht, Ph.D., Research Director Pacific Basin Research and >Training Center >1268 Young Street, Suite #204 >Research Center, University of Hawaii >Honolulu, HI 96814 >E-mail <[hidden email]> >Phone 808-592-5904, FAX 808-592-5909 |
At 12:14 PM 9/19/2006, Peck, Jon wrote:
>Well, as it happens, by taking advantage of programmability features >in SPSS 15, vector-valued functions are easy to create. Initially the >module for this, named trans, is part of the Bonus Pack for early >adopters of SPSS 15, but it will be generally available on Developer >Central after the Directions conference in early November. Well, WHAT do you know. Truly neat. Thank you, Jon! >In the program below, the Python function vectorroot is defined as >returning a list of square roots of each of the variables it is called >with. > >The key part is the t.append line. This applies the function >vectorroot to each variable in that list and creates new numeric >variables with names like sqrt_educ. The t.execute line actually >passes the data. (Yes, Richard, you do need this form of execute here >:-)) > > >begin program. >import spssaux, trans, spss, math > >spssaux.OpenDataFile("c:/spss15/employee data.sav") > >def vectorroot(*vars): > return [math.sqrt(v) for v in vars] > > >d = spssaux.VariableDict() > ># "EducToPrevexp" is equivalent to "educ TO prevexp". >EducToPrevexp = d.range('educ', 'prevexp') >numvars = len(EducToPrevexp) >t = trans.Tfunction() >t.append(vectorroot, ['sqrt_'+v for v in EducToPrevexp], >numvars*['f'], EducToPrevexp) >t.execute() >end program. > >The Bonus Pack includes both the trans module and a collection of >useful, nontrivial functions such as a soundex function that can be >applied this way. Thanks! Richard |
Free forum by Nabble | Edit this page |