Using macro value in custom table

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

Using macro value in custom table

e.spss
I have a python script that generates a list of variable according tot variable name (qs1, qs2, etc.) and subsequently sets a macro value (!varlist in this case) for this list. I want to use the macro value to generate a custom table. My code is now as follows:

CTABLES
  /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
  /TABLE !varlist [TABLEPCT.COUNT PCT5.0]
  /SLABELS VISIBLE=NO
  /CLABELS ROWLABELS=OPPOSITE
  /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.



The problem in the command is in the bold part. Execution of this command ends in the following warning:

TABLE: Text qs2. An invalid subcommand, keyword, or option was specified. Execution of this command stops.



If I change the bold part as follow, the code works, but the whole advantage of the macro value is lost:

CTABLES
  /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
  /TABLE qs1 [TABLEPCT.COUNT PCT5.0] + qs2 [TABLEPCT.COUNT PCT5.0] + etc.
  /SLABELS VISIBLE=NO
  /CLABELS ROWLABELS=OPPOSITE
  /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.


Tried a lot of different things and searched the internet for two days now. So my question: can anyone tell me how to use the macro value properly in a ctables command?
Thanks a million!

Elmer
Reply | Threaded
Open this post in threaded view
|

Re: Using macro value in custom table

David Marso
Administrator
My ESP tells me that you need to read up on the DEFINE !ENDDEFINE command
(and probably python too)!
See !DO !DOEND .
I suspect that the first syntax ends up as:
CTABLES
  /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
  /TABLE qs1 qs2 [TABLEPCT.COUNT PCT5.0]
  /SLABELS VISIBLE=NO
  /CLABELS ROWLABELS=OPPOSITE
  /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.

which is NOT valid.
BTW: The !cpy/!TAIL/!IF biz is simply to  suppress the final + .
---
You need something modeled from this example ( leaving you to apply it):
DEFINE blah (varlist !CMDEND).
  !LET !cpy=!varlist
  !LET !vl=""
  !DO !V !IN(!varlist)
    !LET !vl=!CONCAT(!vl,!V,"[blah blah blah]")
    !LET !cpy=!TAIL(!cpy)
    !IF (!cpy !NE !NULL) !THEN
      !LET !vl=!CONCAT(!vl,"+")
    !IFEND
  !DOEND
STRING TEST(A100).
COMPUTE TEST=!QUOTE(!vl).
PRINT /TEST .
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.
DATA LIST FREE / x.
begin data
1
END DATA.
blah varlist a b c d.
EXE.

blah varlist a b c d.
 159  0 M>  
 160  0 M>  .
 161  0 M>  STRING TEST(A100).
 162  0 M>  COMPUTE TEST= 'a[blah blah blah]+b[blah blah blah]+c[blah blah blah]+d[blah blah blah]'.
 163  0 M>  PRINT /TEST
 164  0 M>   .
EXE.
 165  0 M>  EXE.
a[blah blah blah]+b[blah blah blah]+c[blah blah blah]+d[blah blah blah]

e.spss wrote
I have a python script that generates a list of variable according tot variable name (qs1, qs2, etc.) and subsequently sets a macro value (!varlist in this case) for this list. I want to use the macro value to generate a custom table. My code is now as follows:

CTABLES
  /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
  /TABLE !varlist [TABLEPCT.COUNT PCT5.0]
  /SLABELS VISIBLE=NO
  /CLABELS ROWLABELS=OPPOSITE
  /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.



The problem in the command is in the bold part. Execution of this command ends in the following warning:

TABLE: Text qs2. An invalid subcommand, keyword, or option was specified. Execution of this command stops.



If I change the bold part as follow, the code works, but the whole advantage of the macro value is lost:

CTABLES
  /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
  /TABLE qs1 [TABLEPCT.COUNT PCT5.0] + qs2 [TABLEPCT.COUNT PCT5.0] + etc.
  /SLABELS VISIBLE=NO
  /CLABELS ROWLABELS=OPPOSITE
  /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.


Tried a lot of different things and searched the internet for two days now. So my question: can anyone tell me how to use the macro value properly in a ctables command?
Thanks a million!

Elmer
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Using macro value in custom table

Jon K Peck
In reply to this post by e.spss
I can't quite tell what you are doing here.  A more complete description would help.

Are you using spss.SetMacroValue to define the macro?
Do you have the variable list parenthesized and joined with a proper tables expression, .e.g.,
(a+b+c)?
Are you using spss.Submit to run the request, or is this happening after the program in the regular syntax stream?

Have you tried SET MPRINT ON to see how the macro is actually expanded?

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        "e.spss" <[hidden email]>
To:        [hidden email]
Date:        05/25/2012 04:58 AM
Subject:        [SPSSX-L] Using macro value in custom table
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I have a python script that generates a list of variable according tot
variable name (qs1, qs2, etc.) and subsequently sets a macro value
(*!varlist* in this case) for this list. I want to use the macro value to
generate a custom table. My code is now as follows:

CTABLES
 /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
*  /TABLE !varlist [TABLEPCT.COUNT PCT5.0] *
 /SLABELS VISIBLE=NO
 /CLABELS ROWLABELS=OPPOSITE
 /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.



The problem in the command is in the bold part. Execution of this command
ends in the following warning:

TABLE: Text opening2. An invalid subcommand, keyword, or option was
specified. Execution of this command stops.



If I change the bold part as follow, the code works, but the whole advantage
of the macro value is lost:

CTABLES
 /VLABELS VARIABLES=!varlist DISPLAY=DEFAULT
*  /TABLE qs1 [TABLEPCT.COUNT PCT5.0] + qs2 [TABLEPCT.COUNT PCT5.0] + etc.*
 /SLABELS VISIBLE=NO
 /CLABELS ROWLABELS=OPPOSITE
 /CATEGORIES VARIABLES=!varlist ORDER=A KEY=VALUE EMPTY=EXCLUDE.


Tried a lot of different things and searched the internet for two days now.
So my question: can anyone tell me how to use the macro value properly in a
ctables command?
Thanks a million!

Elmer

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Using-macro-value-in-custom-table-tp5713363.html
Sent from the SPSSX Discussion mailing list archive at 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