!do-!doend question

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

!do-!doend question

Guido Schiffhorst

Hi,

 

The following „macro_wo_loop“ brings "Z" to the screen, the other one („macro_loop“) with an additional loop around it presents "*" and some error messages I can't assign.

 

Is there a working way to call another macro inside a !do-!doend loop and pass an argument?

 

Best

Guido

 

--

output close all.

dataset close all.

new file.

 

DATA LIST LIST/ X Y Z (3 A1).

BEGIN DATA

    F F A

    R B B

END DATA.

save outfile = 'c:\temp\d.sav'.

 

dataset close all.

new file.

 

define macro1 (pop !tokens(1))

echo !quote(!pop).

!enddefine.

 

define macro_loop (v !tokens(1))

    !do !i = 1 !to 1

        get file = 'c:\temp\d.sav'.

        do if $casenum = 1.

            write outfile = 'c:\temp\foo.sps'

            /'macro1 pop =' !quote(!v) '.'.

        end if.

        exe.

        insert file = 'c:\temp\foo.sps'.

    !doend

!enddefine.

 

define macro_wo_loop (v !tokens(1))

    get file = 'c:\temp\d.sav'.

    do if $casenum = 1.

        write outfile = 'c:\temp\foo.sps'

        /'macro1 pop =' !quote(!v) '.'.

    end if.

    exe.

    insert file = 'c:\temp\foo.sps'.

!enddefine.

 

 

macro_wo_loop v = Z.

 

macro_loop v = Z.

 

 

 

 

 

 

 

 

===================== 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: !do-!doend question

David Marso-2
Get rid of the whole condional horrible  hack bullshit and just call the stupid macro. What are you attempting to achieve with this?

=====================
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
|

Aw: Re: !do-!doend question

Guido Schiffhorst
Good morning
 
macro1 handles the drawing of a control group according to a prespecified algorithm for a different patient population each time (pop).
macro_loop iterates over a feature to be balanced by selecting suitable control patients (via macro1).
I can define macro1 for each patient population separately, as I did (i.e. macro1_Pop1, macro1_Pop2 etc.), the script would be shorter if I could pass the respective population by argument. I try to understand why this doesn't work within a !do-!doend loop.
 
Guido
 
Gesendet: Donnerstag, 20. Mai 2021 um 13:40 Uhr
Von: "David Marso" <[hidden email]>
An: [hidden email], [hidden email]
Betreff: Re: !do-!doend question
Get rid of the whole condional horrible hack bullshit and just call the stupid macro. What are you attempting to achieve with this?
 
===================== 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
|

Aw: Re: !do-!doend question

Guido Schiffhorst
In reply to this post by Guido Schiffhorst
Hi, thank you. But no, it doesn't solve the problem. !eval(!pop) leads to the same results. 'Z' without loop, '*' and errors within a !do-!doend loop
 
 
Gesendet: Donnerstag, 20. Mai 2021 um 21:31 Uhr
Von: "PRogman" <[hidden email]>
An: [hidden email]
Betreff: Re: !do-!doend question
See if the !EVAL() function can solve your argument problems.
/PR



--
Sent from: http://spssx-discussion.1045642.n5.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
===================== 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: Aw: Re: !do-!doend question

David Marso-2
In reply to this post by Guido Schiffhorst
Perhaps the error messages are relavant to diagnosis.  Post them. Also use SET MPRINT ON before running  the macro and post those results along with current code. Hopefully you have ditched that DO IF .. WRITE garbage.  Utterly unnecessay. Don't require !EVAL either. Also state your  purpose in this macro. May also want to look at !IN operator for looping in a macro. There are examples of macros calling other macros all over this list. Mostly posted by yours truly over the years.

=====================
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: !do-!doend question

Kirill Orlov
This post was updated on .
In reply to this post by Guido Schiffhorst
Hi, Guido.
This is the first time I see this sort of error.
And I think it is an SPSS bug worth to submit it to the developers.

[I hope that Jon, David and other gurus might want to consider the case.
Because it is interesting.
The topic is: INSERTing macro calls WRITE/tten within the same macro.]

Below is a an example and a workaround.
I was using your data and the syntax is just a little bit rewritten yours.

DATA LIST LIST/ X Y Z (3 A1).
BEGIN DATA
     F F A
     R B B
END DATA.
save outfile = 'c:\temp\d.sav'.
dataset close all.

define !macro1(pop=!tokens(1))
echo !quote(!pop).
!enddefine.

define !macro_loop(v=!tokens(1))
!do !i = 1 !to 2
-get file = 'c:\temp\d.sav'.
-do if $casenum = 1.
- write outfile = !quote(!conc('c:\temp\foo',!i,'.sps'))
     /'!macro1 pop = ' !quote(!conc(!v,!i)) '.'.
-end if.
-exe.
-insert file = !quote(!conc('c:\temp\foo',!i,'.sps')) .
!doend
!enddefine.

!macro_loop v = Z. /*The macro call
*This macro is like yours main one, only it has 2 loops instead of 1.
*[Also, it WRITEs to different files (foo1.sps and foo2.sps) on
different macro loops,
*but that makes no difference: one could write into one same file
foo.sps, like your macro did it.]
*And on the second loop it returns the same ERROR like yours did.
*The macro generates (set printback=on) the syntax below which, when pasted
*and run manually from the syntax window, runs smoothly: .
get file = 'c:\temp\d.sav'.
do if $casenum = 1.
-write outfile = 'c:\temp\foo1.sps' /'!macro1 pop = ' 'Z1' '.'.
end if.
exe.
insert file = 'c:\temp\foo1.sps'.
get file = 'c:\temp\d.sav'.
do if $casenum = 1.
-write outfile = 'c:\temp\foo2.sps' /'!macro1 pop = ' 'Z2' '.'.
end if.
exe.
insert file = 'c:\temp\foo2.sps'.

*So, The syntax generated (expanded) is all right, and the error occurs
when "the macro runs" the syntax it has expanded.
*The error is associated with the second INSERT command (insert file =
'c:\temp\foo2.sps',
*containing syntax: !macro1 pop = Z2.). It is not parsed properly.
*So the LAST macro loop with its corresponding INSERT is problematic in
this respect.

*If you insist on WRITEing out macro calls and INSERTing them on the
same macro loops,
*I might recommed you the following simple trick. Just request one more
macro loop than needed, and do not
*use INSERT on that last macro loop: .
define !macro_loop(v=!tokens(1))
!do !i = 1 !to 3
-get file = 'c:\temp\d.sav'.
-do if $casenum = 1.
- write outfile = !quote(!conc('c:\temp\foo',!i,'.sps'))
     /'!macro1 pop = ' !quote(!conc(!v,!i)) '.'.
-end if.
-exe.
!IF (!i<>3) !THEN
-insert file = !quote(!conc('c:\temp\foo',!i,'.sps')) .
!IFEND
!doend
!enddefine.

!macro_loop v = Z. /*The macro call: No error now.



20.05.2021 9:16, Guido Schiffhorst пишет:
>
> define macro1 (pop !tokens(1))
>
> echo !quote(!pop).
>
> !enddefine.
>
> define macro_loop (v !tokens(1))
>
>     !do !i = 1 !to 1
>
>         get file = 'c:\temp\d.sav'.
>
>         do if $casenum = 1.
>
>             write outfile = 'c:\temp\foo.sps'
>
>             /'macro1 pop =' !quote(!v) '.'.
>
>         end if.
>
>         exe.
>
>         insert file = 'c:\temp\foo.sps'.
>
>     !doend
>
> !enddefine.
>
> define macro_wo_loop (v !tokens(1))
>
>     get file = 'c:\temp\d.sav'.
>
>     do if $casenum = 1.
>
>         write outfile = 'c:\temp\foo.sps'
>
>         /'macro1 pop =' !quote(!v) '.'.
>
>     end if.
>
>     exe.
>
>     insert file = 'c:\temp\foo.sps'.
>
> !enddefine.
>
> macro_wo_loop v = Z.
>
> macro_loop v = Z.
>


=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: Aw: Re: !do-!doend question

David Marso-2
In reply to this post by Guido Schiffhorst
https://listserv.uga.edu/cgi-bin/wa?A2=ind1312&L=SPSSX-L&P=R40367&X=9B2E1277B5BDEEC4CE&Y=Dmmugaspss%40gmail.com

For examples.  Follow the entire thread and your brain might short circuit. It becomes interesting and useful about four or five posts into the thread.

=====================
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: Aw: Re: !do-!doend question

Art Kendall
I am trying to follow this.  We may have a difference in disciplinary word
usage.

Do you have an experimental or a quasi-experimental study?
You mention a control group, but I do not see any random assignment. Do you
mean a comparison group with similar characteristics?

You have a population of patient records.  Is a different population say a
different hospital?

More specific examples of what you are trying to do might help us help you.








-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Aw: Re: !do-!doend question

PRogman
In reply to this post by Guido Schiffhorst
!eval() does not change anything here. I tried early to edit my post but
somehow lost it(?).

It is a strange behavior. After SET MPRINT ON the output from the macro
without !do-loop displays:
...
2188  0  macro1 pop =Z.
2188  0 M>  .
Z
2189  0  
2189  0 M>  
2190  0  * End of INSERT and INCLUDE nesting level 01.
2190  0 M>  * End of INSERT and INCLUDE nesting level 01.

whereas with the !do-loop it is:
...
2121  0  macro1 pop =Z.
2122  0  
2122  0 M>  echo '*'
*
2123  0 M>   of INSERT and INCLUDE nesting level 01.
 
>Error # 1.  Command name: of
>The first word in the line is not recognized as an SPSS Statistics command.
>Execution of this command stops.
2124  0 M>   =Z.
 
>Error # 1.  Command name: =Z
>The first word in the line is not recognized as an SPSS Statistics command.
>Execution of this command stops.

It seems like part of the system-inserted comment are mixed with the insert
file command. The data written to foo.sps is correct. Notice (in line 2123
above) that 5 characters are missing '* End' and the argument to macro1 is
'*', then 'macro1 pop' is missing and only a '=Z' is executed and fails.

Surely this is a bug...

/PR



Guido Schiffhorst wrote
> Hi, thank you. But no, it doesn&#39;t solve the problem. !eval(!pop) leads
> to the same results. &#39;Z&#39; without loop, &#39;*&#39; and errors
> within a !do-!doend loop
>
> &nbsp;
> &nbsp;
>
> Gesendet:&nbsp;Donnerstag, 20. Mai 2021 um 21:31 Uhr
> Von:&nbsp;&quot;PRogman&quot; &lt;

> peder@

> &gt;
> An:&nbsp;

> SPSSX-L@.UGA

>  
> Betreff:&nbsp;Re: !do-!doend question
>
> See if the !EVAL() function can solve your argument problems.
> /PR
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ 
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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
>
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>   (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





--
Sent from: http://spssx-discussion.1045642.n5.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: !do-!doend question

Kirill Orlov
In reply to this post by Guido Schiffhorst
I am sure that this is a bug of macro facility.

In my previous response I've shown a remedy.
But here is a simpler one!
Just insert an idle command or text after the !doend, and the error will
dissapear: .

define !macro_loop(v=!tokens(1))
!do !i = 1 !to 2
-get file = 'c:\temp\d.sav'.
-do if $casenum = 1.
- write outfile = !quote(!conc('c:\temp\foo',!i,'.sps'))
     /'!macro1 pop = ' !quote(!conc(!v,!i)) '.'.
-end if.
-exe.
-insert file = !quote(!conc('c:\temp\foo',!i,'.sps')).
!doend
*.
!enddefine.

!macro_loop v = Z.

=====================
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
|

AW: !do-!doend question

Guido Schiffhorst
Fascinating, i.e. the parser needs a kind of terminator to execute the last
iteration without error?! Bug or feature... anyway... thank you very much
Kirill for this solution!!!.


-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von
Kirill Orlov
Gesendet: Freitag, 21. Mai 2021 18:47
An: [hidden email]
Betreff: Re: !do-!doend question

I am sure that this is a bug of macro facility.

In my previous response I've shown a remedy.
But here is a simpler one!
Just insert an idle command or text after the !doend, and the error will
dissapear: .

define !macro_loop(v=!tokens(1))
!do !i = 1 !to 2
-get file = 'c:\temp\d.sav'.
-do if $casenum = 1.
- write outfile = !quote(!conc('c:\temp\foo',!i,'.sps'))
     /'!macro1 pop = ' !quote(!conc(!v,!i)) '.'.
-end if.
-exe.
-insert file = !quote(!conc('c:\temp\foo',!i,'.sps')).
!doend
*.
!enddefine.

!macro_loop v = Z.

=====================
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

=====================
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
|

AW: Aw: Re: !do-!doend question

Guido Schiffhorst
In reply to this post by Art Kendall
Art, sorry, I've deleted everything not associated with the error from the
macros.
I have a quasi-experimental study and I need to balance therapy lines
between to patient populations following a prespecified pseudo-algorithm in
a study protocol/SAP. I am done but my program could be shorter (and more
elegant if I get David right). I stumbled over that runtime error I've
posted. Thanks to Kirill who solved the issue!
 


-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von
Art Kendall
Gesendet: Freitag, 21. Mai 2021 16:08
An: [hidden email]
Betreff: Re: Aw: Re: !do-!doend question

I am trying to follow this.  We may have a difference in disciplinary word
usage.

Do you have an experimental or a quasi-experimental study?
You mention a control group, but I do not see any random assignment. Do you
mean a comparison group with similar characteristics?

You have a population of patient records.  Is a different population say a
different hospital?

More specific examples of what you are trying to do might help us help you.








-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.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

=====================
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
|

AW: Aw: Re: !do-!doend question

Guido Schiffhorst
In reply to this post by David Marso-2
Nope, I'll stay with that DO IF ... WRITE garbage since Kirill found a nice solution and I understand what I'm doing. Got it years ago from Raynalds page and it worked many times. But I will try DoSomething and DoSomethingElse (thank you for the link!) one day.


-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von David Marso
Gesendet: Freitag, 21. Mai 2021 14:03
An: [hidden email]
Betreff: Re: Aw: Re: !do-!doend question

Perhaps the error messages are relavant to diagnosis.  Post them. Also use SET MPRINT ON before running  the macro and post those results along with current code. Hopefully you have ditched that DO IF .. WRITE garbage.  Utterly unnecessay. Don't require !EVAL either. Also state your  purpose in this macro. May also want to look at !IN operator for looping in a macro. There are examples of macros calling other macros all over this list. Mostly posted by yours truly over the years.

=====================
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

=====================
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: AW: Aw: Re: !do-!doend question

Kirill Orlov
WRITE - then - INSERT trick which David calls "horrible hack" is in fact
very useful, often needed doing.


21.05.2021 23:07, Guido Schiffhorst пишет:
> Nope, I'll stay with that DO IF ... WRITE garbage since Kirill found a nice solution and I understand what I'm doing. Got it years ago from Raynalds page and it worked many times. But I will try DoSomething and DoSomethingElse (thank you for the link!) one day.
>
>

=====================
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: AW: Aw: Re: !do-!doend question

Jon Peck
Or just use Python, which is more powerful, elegant, and automatically installed with Statistics.

On Fri, May 21, 2021 at 2:50 PM Kirill Orlov <[hidden email]> wrote:
WRITE - then - INSERT trick which David calls "horrible hack" is in fact
very useful, often needed doing.


21.05.2021 23:07, Guido Schiffhorst пишет:
> Nope, I'll stay with that DO IF ... WRITE garbage since Kirill found a nice solution and I understand what I'm doing. Got it years ago from Raynalds page and it worked many times. But I will try DoSomething and DoSomethingElse (thank you for the link!) one day.
>
>

=====================
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


--
Jon K Peck
[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