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

Macro variable to Python string?

1,399 views
Skip to first unread message

RJ2

unread,
Oct 27, 2008, 4:49:59 PM10/27/08
to
I'm trying to push a macro variable to a string value in python.

The value is defined like this:

define !date()
'081027'
enddefine.

In regular spss code, I can simply put !date() and it resolves exactly
the way I want it. However, I want to push it into Python to use it
with a python defined procedure.

Anyone have some insight?

JKPeck

unread,
Oct 28, 2008, 12:08:01 PM10/28/08
to

Not sure what you want. You can use macros in syntax you run with
spss.Submit, and you can define
macros in Python with spss.SetMacroValue for use in SPSS syntax. But
you can't use a macro value
in Python syntax. If you want to pass a value to Python code as a
parameter, the most direct way, of
course, is to make it a parameter of a Python function and just call
that function in a BEGIN PROGRAM
block.

There are two other ways that come to mind, though, if the approach
above doesn't work for you.
You could create a custom attribute in syntax like
DATAFILE ATTRIBUTE ATTRIBUTE=Date("081027").
(That becomes a persistent part of the data file, BTW).
Then using Python code, you can fetch this using
spss.GetDataFileAttributes("Date")
and use it however you like.

You could also create an extension command using version 16 or later
and have it take the macro value as
a keyword or leading token The value would then be passed to your
code as a parameter.

HTH,
Jon Peck

RJ2

unread,
Nov 3, 2008, 10:57:09 AM11/3/08
to

Excellent! Thank you!


I used the spss.SetMacroValue function to delcare the macro variable.
Works like a charm.

0 new messages