Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nested do repeats?

207 views
Skip to first unread message

Andy W

unread,
Jun 24, 2010, 2:53:10 PM6/24/10
to
Hello,

I am trying to make a statement that evaluates if a set of strings are
equal and then assigns another variable a value of 1 if they are
equal. Where I am encountering a problem is trying to get the do
repeat to loop through two seperate vectors of variables.

I suppose it is easier to show the syntax than to explain in words

****so here is a command that does work in my program.

do repeat check = check1 to check12
/n_check = n_check1 to n_check12.
if qgram1= check n_check = 1.
end repeat.
execute.

Andy W

unread,
Jun 24, 2010, 2:58:22 PM6/24/10
to
sorry about that I somehow hit send, so as to elaborate further

I suppose it is easier to show the syntax than to explain in words

****so here is a command that does work in my program.

do repeat check = check1 to check12
/n_check = n_check1 to n_check12.
if qgram1= check n_check = 1.
end repeat.
execute.

*but I want to use a vector of variables in replace of qgram1, so I
want to use qgram1 to qgram12.

I have attempted several other incarnations that do not work, such as
***************************************************.
loop i = 1 to 12.


do repeat check = check1 to check12
/n_check = n_check1 to n_check12.

do if qgram(i) = check.
compute n_check = 1.
end if.
end repeat.
end loop.
execute.
************************************************.

And defining a macro with my qgram variables.
************************************************.
define !qgram () qgram1 to qgram12.
!enddefine.


do repeat check = check1 to check12
/n_check = n_check1 to n_check12.

if !qgram = check n_check = 1.
end repeat.
execute.
**********************************************,

Does anyone think they can help? Do I have to define loops within a
macro to accomplish this?

Thank you for your time,
Andy W

Rich Ulrich

unread,
Jun 24, 2010, 4:40:10 PM6/24/10
to
On Thu, 24 Jun 2010 11:58:22 -0700 (PDT), Andy W <apwh...@gmail.com>
wrote:

That proposed syntax results in !qgram being replaced by
the text < qgram1 to qgram12> ... which will not be legal code.

I think you can use the ANY( ) function in order to generate
the results that you want. ANY( ) returns TRUE or 1 when the
first argument matches any of the list that follows.

For easier reading, I would not use the qgram Macro.
Just replace the IF with

if any(check, qgram1 to qgram12) n_check=1.

--
Rich Ulrich

Bruce Weaver

unread,
Jun 24, 2010, 4:58:13 PM6/24/10
to

I think you're close to something that will work with your LOOP. Try
it with a VECTOR command in front of it, like this:

vector qgram = qgram1 to qram12.
loop #i = 1 to 12.


do repeat check = check1 to check12
/n_check = n_check1 to n_check12.

- if qgram(#i) = check n_check = 1.
end repeat.
end loop.
execute.

I expect nested DO-REPEATS would work too.

do repeat qgram = qgram1 to qram12.
- do repeat
check1 to check12 /
n_check = n_check1 to n_check12.
- if qgram = check n_check = 1.
- end repeat.
end repeat.
exe.

Notice that I changed your DO-IF to a simple IF, because there was
only one condition. What do you want to do if the qgram does NOT
equal check? I.e., do you need to initialize your n_check variables
to 0?

--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."

Ben Pfaff

unread,
Jun 24, 2010, 5:07:26 PM6/24/10
to
Bruce Weaver <bwe...@lakeheadu.ca> writes:

> I expect nested DO-REPEATS would work too.

I'm not sure that it's supposed to. The SPSS command syntax
reference has a very explicit list of commands allowed within DO
REPEAT. DO REPEAT itself does not appear on that list.
--
Ben Pfaff
http://benpfaff.org

Andy W

unread,
Jun 24, 2010, 9:28:51 PM6/24/10
to
Thank you everyone,

Both Mr. Weaver's and Mr. Ulrich's suggestions worked. The nested do
loop command did not work, and returned an error mentioning a do
repeat command is not allowed inside a do repeat as Mr. Pfaff
suggested.

Thank you for your time and your speedy responses.
Andy W

0 new messages