Quick question about Select if within Do Repeat

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

Re: Quick question about Select if within Do Repeat

Jon K Peck
First, with such a big dataset, have you considered using Statistics Server?

Second, "I still don't understand why:

Do repeat ab= test1 to test10.
if (ab=1) pick=1.
end repeat.

acts like an OR
"
An IF statement does nothing if its condition is not satisfied, so the value of pick will not change unless the predicate is true for some ab in the repeat.  Maybe you are thinking it would act like
if ... pick=1
else pick = 0
but the simple IF has no else.
DO IF provides else conditions.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        devoidx <[hidden email]>
To:        [hidden email],
Date:        05/20/2014 11:00 AM
Subject:        Re: [SPSSX-L] Quick question about Select if within Do Repeat
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Well looks like I am going to have to live with it ..just wanted to make sure
I'm not missing any obvious strategies that do not require creating new
variables.

If you were dealing with a multi-billion case database on an average
computer, you would perhaps understand better why I am trying find a code
with with the least number of computations etc in it.

To be honest I still don't understand why:

Do repeat ab= test1 to test10.
if (ab=1) pick=1.
end repeat.

acts like an OR when assigning the "pick" values while:

Do repeat ab= test1 to test10.
select if (ab=1).
end repeat.

acts like an AND.

But i think we're beating a dead horse here so thanks for all the help!



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Quick-question-about-Select-if-within-Do-Repeat-tp5726138p5726158.html
Sent from the SPSSX Discussion mailing list archive at 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: Quick question about Select if within Do Repeat

Rich Ulrich
In reply to this post by David Marso
There are THREE possible implementations that I see for
parsing multiple SELECT IFs -- AND, OR, or "use the last."

I pointed out before the awful hazard of using OR:  It undoes
the restrictive "Select if" that you put in at the start of the code,
and that you were depending on, many days and many lines later.

"Use the last" has the same consequence, *but* it might be
rationalized and even excused if there were some strong reason
(and clear documentation) stating that you can only use ONE
Select if  in a section of code between File-reads.  I think I
mentioned that I don't remember using more than one SELECT IF
- doing it that way let me avoid worrying about the options.

--
Rich Ulrich


 


Reply | Threaded
Open this post in threaded view
|

Re: Quick question about Select if within Do Repeat

devoidx
In reply to this post by David Marso
lol thanks! I'll try out  the bigassfuglyselect code!
Reply | Threaded
Open this post in threaded view
|

Re: Quick question about Select if within Do Repeat

devoidx
Yeah I am starting to understand why Select if doesn't behave the way I would have thought it would within the Do Repeat...thanks guys
Reply | Threaded
Open this post in threaded view
|

Re: Quick question about Select if within Do Repeat

David Marso
Administrator
In reply to this post by devoidx
This one is much better (also shorter , cleaner and gentler wrt calling syntax)!
I suffered a temporary RCI and the factoid that ANY supports TO on the right side was dislodged from my brain.

DEFINE BigFUGLYSELECTv3 (vars !CHAREND("/") /values !CMDEND).
!LET !SEL="SELECT IF ANY(1," !LET !Cpy=!values
!DO !V !IN (!Values)
!LET !Cpy=!TAIL(!Cpy) !LET !SEL=!CONCAT(!SEL,'ANY(',!V,",",!vars,")")
!IF (!cpy !NE !NULL) !THEN !LET !SEL=!CONCAT(!SEL,",") !IFEND
!DOEND
!LET !SEL=!CONCAT(!SEL,")")
!SEL
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

BigFUGLYSELECTv3 vars x1 TO x5 / values 1 2 3 4 5 .
LIST.

creates  
SELECT IF ANY(1,ANY(1,x1 TO x5),ANY(2,x1 TO x5),ANY(3,x1 TO x5),ANY(4,x1 TO x5),ANY(5,x1 TO x5))
BigFUGLYSELECTv3 vars x1, x2, x3, x4, x5 / values 1 2 3 4 5 .
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Quick question about Select if within Do Repeat

devoidx
Thanks a bunch David.
Reply | Threaded
Open this post in threaded view
|

Re: Quick question about Select if within Do Repeat

David Marso
Administrator
In reply to this post by David Marso
Fiddle, fiddle.....How minimal is possible?
Epiphany!!!
All this time I've mucked around with !CONCAT and internal variables! DOH!
-------------------------------------------------------------------------------------
DEFINE BigFuglySelect (vars !CHAREND("/") /values !CMDEND).  
SELECT IF ANY(1, !DO !V !IN (!Values) ANY(!V,!vars), !DOEND 0).
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

BigFuglySelect vars x1 TO x5 / values 1 2 3 4 5 .
LIST.
Yields:
SELECT IF ANY(1, ANY(1,x1 TO x5), ANY(2,x1 TO x5), ANY(3,x1 TO x5), ANY(4,x1 TO x5), ANY(5,x1 TO x5), 0).


David Marso wrote
This one is much better (also shorter , cleaner and gentler wrt calling syntax)!
I suffered a temporary RCI and the factoid that ANY supports TO on the right side was dislodged from my brain.

DEFINE BigFUGLYSELECTv3 (vars !CHAREND("/") /values !CMDEND).
!LET !SEL="SELECT IF ANY(1," !LET !Cpy=!values
!DO !V !IN (!Values)
!LET !Cpy=!TAIL(!Cpy) !LET !SEL=!CONCAT(!SEL,'ANY(',!V,",",!vars,")")
!IF (!cpy !NE !NULL) !THEN !LET !SEL=!CONCAT(!SEL,",") !IFEND
!DOEND
!LET !SEL=!CONCAT(!SEL,")")
!SEL
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

BigFUGLYSELECTv3 vars x1 TO x5 / values 1 2 3 4 5 .
LIST.

creates  
SELECT IF ANY(1,ANY(1,x1 TO x5),ANY(2,x1 TO x5),ANY(3,x1 TO x5),ANY(4,x1 TO x5),ANY(5,x1 TO x5))
BigFUGLYSELECTv3 vars x1, x2, x3, x4, x5 / values 1 2 3 4 5 .
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Quick question about Select if within Do Repeat

Bruce Weaver
Administrator
Very nice!  http://www.youtube.com/watch?v=TAryFIuRxmQ   ;-)


David Marso wrote
Fiddle, fiddle.....How minimal is possible?
Epiphany!!!
All this time I've mucked around with !CONCAT and internal variables! DOH!
-------------------------------------------------------------------------------------
DEFINE BigFuglySelect (vars !CHAREND("/") /values !CMDEND).  
SELECT IF ANY(1, !DO !V !IN (!Values) ANY(!V,!vars), !DOEND 0).
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

BigFuglySelect vars x1 TO x5 / values 1 2 3 4 5 .
LIST.
Yields:
SELECT IF ANY(1, ANY(1,x1 TO x5), ANY(2,x1 TO x5), ANY(3,x1 TO x5), ANY(4,x1 TO x5), ANY(5,x1 TO x5), 0).


David Marso wrote
This one is much better (also shorter , cleaner and gentler wrt calling syntax)!
I suffered a temporary RCI and the factoid that ANY supports TO on the right side was dislodged from my brain.

DEFINE BigFUGLYSELECTv3 (vars !CHAREND("/") /values !CMDEND).
!LET !SEL="SELECT IF ANY(1," !LET !Cpy=!values
!DO !V !IN (!Values)
!LET !Cpy=!TAIL(!Cpy) !LET !SEL=!CONCAT(!SEL,'ANY(',!V,",",!vars,")")
!IF (!cpy !NE !NULL) !THEN !LET !SEL=!CONCAT(!SEL,",") !IFEND
!DOEND
!LET !SEL=!CONCAT(!SEL,")")
!SEL
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.

BigFUGLYSELECTv3 vars x1 TO x5 / values 1 2 3 4 5 .
LIST.

creates  
SELECT IF ANY(1,ANY(1,x1 TO x5),ANY(2,x1 TO x5),ANY(3,x1 TO x5),ANY(4,x1 TO x5),ANY(5,x1 TO x5))
BigFUGLYSELECTv3 vars x1, x2, x3, x4, x5 / values 1 2 3 4 5 .
--
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/).
12