Date: Thu, 14 Jun 2007 08:05:54 -0500
Reply-To: "Peck, Jon" <peck@spss.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Peck, Jon" <peck@spss.com>
Subject: Re: How can I automatically display the variable label
as title in spss syntax
In-Reply-To: A<200706140136.l5DIhcSe010778@mailgw.cc.uga.edu>
Content-Type: text/plain; charset="utf-8"
Tables and Ctables do not give you a built-in way to title a title with the variable label since in general there will be several variables in a single table request. However, this is easy to do if you can use programmability, introduced in SPSS 14. Here is a simple example.
First it creates a Python dictionary for the specified variables (this example uses the cars.sav dataset).
Then it loops through the specified variables and submits a TABLES command on the variable name with the variable label as the title. The code substitutes the variable name in the title if there is no variable label.
HTH
begin program.
import spss, spssaux
vardict = spssaux.VariableDict("year origin cylinder")
for var in vardict:
varlabel = var.VariableLabel
if varlabel == "":
varlabel = var.VariableName
spss.Submit("""TABLES /TABLE %s BY (STATISTICS) /TITLE "%s".""" % (var.VariableName, varlabel))
end program.
Regards,
Jon Peck
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Ken Chui
Sent: Wednesday, June 13, 2007 8:37 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: [SPSSX-L] How can I automatically display the variable label as title in spss syntax
Hello, you may change it into a small macro:
* Define the macro name as "vartitle" with a token as "inlist".
DEFINE !vartitle (inlist = !ENCLOSE("(",")")).
!DO !I !IN (!inlist).
TABLES
/FORMAT BLANK MISSING('.')
/TABLES !I
BY (STATISTICS)
/TITLE !QUOTE(!I) .
!DOEND .
!ENDDEFINE .
* Evoke the macro with the variable of your choice.
!vartitle inlist = (income).
EXE .
<><><><><>
If you have multiple varialbe, just expand the "inlist", e.g.
!vartitle inlist = (income gender education ethnicity).
EXE.
Then you should be able to get the tables.
Hope this helps.
Ken
On Wed, 13 Jun 2007 02:57:20 -0400, Kevin Wong <flutter8888@YAHOO.COM.CN> wrote:
>Hello,everybody:
> I always use the spss syntax to create a lot of tables in my work,but I
>am worried about a problem about the titles of the tables.For example:
> * Basic Tables.
>TABLES
> /FORMAT BLANK MISSING('.')
> /TABLES income
> BY (STATISTICS)
> /TITLE 'income'.
>
>Only the constant character string can be specified in the title
>subcommand ,but I hope to automatically display the variable label as
>title in spss syntax ,such as:
>
> * Basic Tables.
>TABLES
> /FORMAT BLANK MISSING('.')
> /TABLES income
> BY (STATISTICS)
> /TITLE var label.
>
>When executed,a warning occurs.
>
>So can you fix this issue in some way?
>Help me!