Macros and Python

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

Macros and Python

Georg Maubach
Dear Listers,

we have develop a large syntax using macros for various program steps.
We would like to extend this program using Python. But when integrating
the new Python code into our macro SPSS responds with

>Error # 6892.  Command name: BEGIN PROGRAM
>The string's length is more than 251.
>This command not executed.


>Error # 1.  Command name: +
>The first word in the line is not recognized as an SPSS command.

Is it possible to use Python code from within macros? If not, is there
some kind of work around?

We would like to add, that we do not want to create the macro using
Python but to run Python code inside an existing macro.

Best regards

Georg Maubach
Research Manager
Reply | Threaded
Open this post in threaded view
|

Re: Macros and Python

Albert-Jan Roskam
Hi Georg,

From the manual, see the last bullet (v14.0, p 174):
Scope and Limitations
�� Programmatic variables created in a
program block cannot be used outside of program
blocks.
However, you can generate SPSS macro variables within
program blocks that can be used
outside program blocks.
�� Program blocks cannot be nested
within program blocks.
�� Program blocks cannot be contained
within DEFINE-!ENDDEFINE macro definitions. <<====
Alas! ;-)

Cheers!!
Albert-Jan

--- Georg Maubach <[hidden email]> wrote:

> Dear Listers,
>
> we have develop a large syntax using macros for
> various program steps.
> We would like to extend this program using Python.
> But when integrating
> the new Python code into our macro SPSS responds
> with
>
> >Error # 6892.  Command name: BEGIN PROGRAM
> >The string's length is more than 251.
> >This command not executed.
>
>
> >Error # 1.  Command name: +
> >The first word in the line is not recognized as an
> SPSS command.
>
> Is it possible to use Python code from within
> macros? If not, is there
> some kind of work around?
>
> We would like to add, that we do not want to create
> the macro using
> Python but to run Python code inside an existing
> macro.
>
> Best regards
>
> Georg Maubach
> Research Manager
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


      ____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
Reply | Threaded
Open this post in threaded view
|

Re: Macros and Python

Richard Ristow
In reply to this post by Georg Maubach
At 06:52 AM 9/12/2007, Georg Maubach wrote:

>Is it possible to use Python code from within macros?

I got this from Jon Peck of SPSS, Inc.:

Essentially, it is not possible. That's because an SPSS macro emits a
single unformatted string. So it can't emit line breaks and indents,
which are crucially syntactic in Python.

I don't know whether defining the Python code as a subroutine within
Python, and then

BEGIN PROGRAM.
<invoke Python subroutine>
END PROGRAM.

would work. Even then, you couldn't pass parameters in to the Python
code via macro arguments.

>Is there some kind of work around? We do not want to create the macro
>using Python but to run Python code inside an existing macro.

Unfortunately, that, which you don't want to do, is what's generally
advised.

-Good luck,
  Richard