GPL and Macro combinations

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

GPL and Macro combinations

Mike P-5
Hello everyone,

I'm currently creating a custom GPL chart, this I have done without any problems,
I am using a macro that does a lot of data manipulations on many variables and then runs this chart.

Here is my question, how can I pass the question names as titles into the GPL programme? For each different variable I am using?
Effectively creating say 50 of my custom charts with titles in one Macro call?

Is this something that can potentially be over come with python?

 

Michael Pearmain

Senior Research Analyst

 twentysix Group

LONDON
Eldon House
1 Dorset Street, London W1U 4EG
T. +44 (0)20 7535 9783
F. +44 (0)20 7535 9801

www.twentysixlondon.com



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: GPL and Macro combinations

Keith McCormick
Hi Michael,

I think you need to try python because python will be able to pull the
variable names (or variable labels which might make a nicer title) out
of the dataset and put it into a list.  Python, I think, also handles
strings much more elegently than macros.

I would suggest visiting http://www.spss.com/devcentral/ and try
simply retrieving names from the active file and printing them out one
at a time.  That should be pretty easy, and then you will have a good
idea how much time you will have to spend on the overall project
sending all or some of those names to SPSS to be added as the title.

There is also a section in http://www.spss.com/spss/data_management_book.htm
that discusses "migrating macros to python".

If you decide to go for it then when you install python (python.org)
you will automatically get IDLE.  In IDLE you can:
import spss, spssaux
help(spss)
help(spssaux)
That will help you find the command you need.

good luck.  hth.

keith
keithmccormick.com




On 6/23/06, Michael Pearmain <[hidden email]> wrote:

> Hello everyone,
>
> I'm currently creating a custom GPL chart, this I have done without any problems,
> I am using a macro that does a lot of data manipulations on many variables and then runs this chart.
>
> Here is my question, how can I pass the question names as titles into the GPL programme? For each different variable I am using?
> Effectively creating say 50 of my custom charts with titles in one Macro call?
>
> Is this something that can potentially be over come with python?
>
>
>
> Michael Pearmain
>
> Senior Research Analyst
>
>  twentysix Group
>
> LONDON
> Eldon House
> 1 Dorset Street, London W1U 4EG
> T. +44 (0)20 7535 9783
> F. +44 (0)20 7535 9801
>
> www.twentysixlondon.com
>
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
Reply | Threaded
Open this post in threaded view
|

Re: GPL and Macro combinations

Peck, Jon
In reply to this post by Mike P-5
This is something that can be done with macro, but it is simpler with Python.  Following is an example using Python.  This example, which is not trying to be chart fancy, finds all the categorical variables in a dataset and creates a bar chart for each.  It uses the variable label as the chart title.

Here is how it works.  First, the variable chartsyntax is defined as a string with all the chart syntax but substitution points for the variable name and the title.  These appear as
%(variable)s and
%(title)s
That notation means to substitute the value of the Python variables named variable and title and to format those values as strings.  For example, %(variable)s might be replaced by "jobcat".

varcat is a VariableDict structure defined as a collection of all the variables in the already open SPSS dataset that have a measurement level of nominal or ordinal.  This structure provides access to all the properties and attributes of the selected SPSS variables.

Finally, the code loops over the variables in varcat, substitutes the variable name and label in the chartsyntax string, prints out the generated syntax, and submits the generated command.


begin program.
# do bar charts of all categorical variables using the variable label as the chart title
import spss, spssaux

chartsyntax=\
"""GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=%(variable)s COUNT()[rename="COUNT"]
 /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
 SOURCE: s=userSource(id("graphdataset"))
 DATA: %(variable)s=col(source(s), name("%(variable)s"), unit.category())
 DATA: COUNT=col(source(s), name("COUNT"))
 GUIDE: axis(dim(1), label("%(variable)s"))
 GUIDE: axis(dim(2), label("Count"))
 GUIDE: text.title(label("%(title)s"))
 SCALE: linear(dim(2), include(0))
 ELEMENT: interval(position(%(variable)s*COUNT))
END GPL.
"""
varcat = spssaux.VariableDict(variableLevel=['nominal', 'ordinal'])
for v in varcat:
        cmd = (chartsyntax % {'variable' : v.VariableName, 'title' : v.VariableLabel})
        print cmd
        spss.Submit(cmd)
end program.

Regards,
Jon Peck
SPSS


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Michael Pearmain
Sent: Friday, June 23, 2006 10:23 AM
To: [hidden email]
Subject: [SPSSX-L] GPL and Macro combinations

Hello everyone,

I'm currently creating a custom GPL chart, this I have done without any problems,
I am using a macro that does a lot of data manipulations on many variables and then runs this chart.

Here is my question, how can I pass the question names as titles into the GPL programme? For each different variable I am using?
Effectively creating say 50 of my custom charts with titles in one Macro call?

Is this something that can potentially be over come with python?



Michael Pearmain

Senior Research Analyst

 twentysix Group

LONDON
Eldon House
1 Dorset Street, London W1U 4EG
T. +44 (0)20 7535 9783
F. +44 (0)20 7535 9801

www.twentysixlondon.com



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________