Macro tokens problem with commas

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

Macro tokens problem with commas

Mike P-5
Hi All,

I'm currently trying to enter a string of variable into another macro call... I want to include the commas as part of the string variable but SPSS seems to recognise the comma as a separator for different tokens.

So my original macro may as below (Shortened for ease of writing, i.e. just showing two tokens)

DEFINE !VARSCOMMA().
"n_4, n_5, n_6, n_7, n_8, n_9" -This is the first string I want entered without ""
"n_10, n_11, n_12, n_13, n_14, n_15" -This is the second string I want entered without ""
!ENDDEFINE.
 
I want to input this into the following macro call

DEFINE !METRICS(!POSITIONAL !TOKENS(10)
                    /!POSITIONAL !TOKENS(10)).
!LET !VIN =!1.
!LET !VOU = !2.
!DO !S !IN (!VIN).
LET !VOUT = !HEAD(!VOU).

*OMS.
DATASET DECLARE Ctables.
OMS
 /SELECT TABLES
 /IF COMMANDS = ["CTables"]
     SUBTYPES = ["Custom Table"]
 /DESTINATION FORMAT = SAV NUMBERED = TableNumber_
  OUTFILE = Ctables
  Viewer = NO.
* Custom Tables.
CTABLES
 /VLABELS VARIABLES=ControlGrp !S DISPLAY=DEFAULT
 /TABLE !S [COUNT F40.0] BY ControlGrp
 /SLABELS VISIBLE=NO
 /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
 /CATEGORIES VARIABLES=!S [!UNQUOTE(!VOUT)] EMPTY=INCLUDE.
CTABLES
  /VLABELS VARIABLES=ControlGrp exposed DISPLAY=DEFAULT
  /TABLE exposed [COUNT F40.0] BY ControlGrp
  /SLABELS VISIBLE=NO
  /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
  /CATEGORIES VARIABLES=exposed ORDER=A KEY=VALUE EMPTY=EXCLUDE.
OMSEND.

SO the bold line reads
 /CATEGORIES VARIABLES=!S [n_4, n_5, n_6, n_7, n_8, n_9] EMPTY=INCLUDE.

Any ideas anyone? Or am I missing a very simple trick?

Thanks in advance


Michael Pearmain


______________________________________________________________________
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: Macro tokens problem with commas

Marta García-Granero
Hi Michael,

Have you tried this MACRO definition? (untested):

DEFINE !METRICS(!POSITIONAL=!CHAREND('/')/!POSITIONAL=!CMDEND).

Then your MACRO call would be:

!METRICS n_4,n_5,n_6,n_7,n_8,n_9 / n_10,n_11,n_12,n_13,n_14,n_15.

MP> I'm currently trying to enter a string of variable into
MP> another macro call... I want to include the commas as part of the
MP> string variable but SPSS seems to recognise the comma as a
MP> separator for different tokens.

MP> So my original macro may as below (Shortened for ease of
MP> writing, i.e. just showing two tokens)

MP> DEFINE !VARSCOMMA().
MP> "n_4, n_5, n_6, n_7, n_8, n_9"              -This is the first string I want entered without ""
MP> "n_10, n_11, n_12, n_13, n_14, n_15"        -This is the second
MP> string I want entered without ""
MP> !ENDDEFINE.

MP> I want to input this into the following macro call

MP> DEFINE !METRICS(!POSITIONAL !TOKENS(10)
MP>                 /!POSITIONAL !TOKENS(10)).
MP> !LET !VIN =!1.
MP> !LET !VOU = !2.
MP> !DO !S !IN (!VIN).
MP> LET !VOUT = !HEAD(!VOU).

MP> *OMS.
MP> DATASET DECLARE Ctables.
MP> OMS
MP>  /SELECT TABLES
MP>  /IF COMMANDS = ["CTables"]
MP>      SUBTYPES = ["Custom Table"]
MP>  /DESTINATION FORMAT = SAV NUMBERED = TableNumber_
MP>   OUTFILE = Ctables
MP>   Viewer = NO.
MP> * Custom Tables.
MP> CTABLES
MP>  /VLABELS VARIABLES=ControlGrp !S DISPLAY=DEFAULT
MP>  /TABLE !S [COUNT F40.0] BY ControlGrp
MP>  /SLABELS VISIBLE=NO
MP>  /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
MP>  /CATEGORIES VARIABLES=!S [!UNQUOTE(!VOUT)] EMPTY=INCLUDE.
MP> CTABLES
MP>   /VLABELS VARIABLES=ControlGrp exposed DISPLAY=DEFAULT
MP>   /TABLE exposed [COUNT F40.0] BY ControlGrp
MP>   /SLABELS VISIBLE=NO
MP>   /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
MP>   /CATEGORIES VARIABLES=exposed ORDER=A KEY=VALUE EMPTY=EXCLUDE.
MP> OMSEND.

MP> SO the bold line reads
MP>  /CATEGORIES VARIABLES=!S [n_4, n_5, n_6, n_7, n_8, n_9] EMPTY=INCLUDE.

HTH,
 Marta                            mailto:[hidden email]
Reply | Threaded
Open this post in threaded view
|

FW: Re: Macro tokens problem with commas

Mike P-5
In reply to this post by Mike P-5
Thanks very much Marta,

I think it works(?), but I still have problems in my definition and I'm not sure where to explore this problem.

I've included most of the syntax I've written (I've taken out lots of data manips as they are not affected by the macro) but I can't figure out where the problem lies?... To me it seems to make sense.

What I am trying to do is for the first entry in each of the three macros run on the !metrics macro, then the second argument of each macro etc etc?

I understand this is on my data, but if you have any ideas of potentially where I might be going wrong I would be most grateful

Many thanks in advance

Mike

Code below



DEFINE !MRGROUP().
Q3MR Q4MR Q5MR Q6MR Q7MR Q8MR Q10aMR Q10bMR Q10cMR Q11MR !ENDDEFINE.

DEFINE !VARSCOMMA().
n_4, n_5, n_6, n_7, n_8, n_9 / n_10, n_11, n_12, n_13, n_14, n_15 / n_16, n_17, n_18, n_19, n_20, n_21 / n_22, n_23, n_24, n_25, n_26 / n_27, n_28, n_29, n_30, n_31 / n_32, n_33, n_34, n_35, n_36, n_37 / n_39, n_40, n_41, n_42, n_43, n_44, n_45, n_46, n_47 / n_48, n_49, n_50, n_51, n_52, n_53, n_54, n_55, n_56 / n_57, n_58, n_59, n_60, n_61, n_62, n_63, n_64, n_65 / n_66, n_67, n_68, n_69, n_70 !ENDDEFINE.

DEFINE !QTITLES()
'Q3 Which of the following cereal brands have you heard of?' 'Q4 Which of the following cereal brands have you seen, read or heard advertised anywhere recently?' 'Q5 Which of the following cereal brands have you seen advertised online recently?'
'Q6 If you were to buy a cereal brand, which of the following would you consider purchasing?' 'Q7 Please indicate how strongly you agree or disagree with each of the following statements about Shreddies'
'Q8 Thinking about cereals, please indicate how strongly you agree or disagree with the following statements?' 'Q10a Thinking about the people in your household when do they tend to eat cereals? SELF'
'Q10b Thinking about the people in your household when do they tend to eat cereals? PARTNER' 'Q10c Thinking about the people in your household when do they tend to eat cereals? KIDS'
"Q11 Thinking about your children's cereals, please indicate how strongly you agree or disagree with the following statements about cereals?"
!ENDDEFINE.

******************************************************************************************************************************************************************************************************************************************************************************************.
***********************************************************************************************************Basic Metrics *****************************************************************************************************************************************************.

DEFINE !METRICS(!POSITIONAL !TOKENS(10)
                    /!POSITIONAL=!CHAREND('/')
                    /!POSITIONAL !TOKENS(10)).
!LET !VIN =!1.
!LET !VOU = !2.
!LET !VOU2 = !3.
!DO !S !IN (!VIN).
!LET !VOUT = !HEAD(!VOU).
!LET !VOUT2 = !HEAD(!VOU2).

*OMS.
DATASET DECLARE Ctables.
OMS
 /SELECT TABLES
 /IF COMMANDS = ["CTables"]
     SUBTYPES = ["Custom Table"]
 /DESTINATION FORMAT = SAV NUMBERED = TableNumber_
  OUTFILE = Ctables
  Viewer = NO.
* Custom Tables.
CTABLES
 /VLABELS VARIABLES=ControlGrp $!S DISPLAY=DEFAULT  /TABLE $!S [COUNT F40.0] BY ControlGrp  /SLABELS VISIBLE=NO  /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE  /CATEGORIES VARIABLES=$!S [!VOUT] EMPTY=INCLUDE.
CTABLES
  /VLABELS VARIABLES=ControlGrp exposed DISPLAY=DEFAULT
  /TABLE exposed [COUNT F40.0] BY ControlGrp
  /SLABELS VISIBLE=NO
  /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
  /CATEGORIES VARIABLES=exposed ORDER=A KEY=VALUE EMPTY=EXCLUDE.
OMSEND.

LOTS OF MANIPS STAGE.

* Custom Tables, This is now the table with the two % of the control and exposed, difference between them and the sig level.
CTABLES
  /VLABELS VARIABLES=p1p p2p Diff SIG_Level DISPLAY=DEFAULT
  /VLABELS VARIABLES=categorys DISPLAY=NONE
  /TABLE categorys BY p1p [MEAN] + p2p [MEAN] + Diff [MEAN] + SIG_Level [MEAN]
  /SLABELS VISIBLE=NO
  /CATEGORIES VARIABLES=categorys ORDER=A KEY=VALUE EMPTY=INCLUDE
  /TITLES
   TITLE= !QUOTE(!UNQUOTE(!VOUT2)).

dataset activate dataset2.
dataset close ctables.

!LET !Vout = !TAIL(!Vout).
!LET !Vout2 = !TAIL(!Vout2).
!DOEND.
!ENDDEFINE.

!METRICS !MRGROUP !VARSCOMMA !QTITLES.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marta García-Granero
Sent: 28 June 2006 16:48
To: [hidden email]
Subject: Re: Macro tokens problem with commas

Hi Michael,

Have you tried this MACRO definition? (untested):

DEFINE !METRICS(!POSITIONAL=!CHAREND('/')/!POSITIONAL=!CMDEND).

Then your MACRO call would be:

!METRICS n_4,n_5,n_6,n_7,n_8,n_9 / n_10,n_11,n_12,n_13,n_14,n_15.

MP> I'm currently trying to enter a string of variable into another
MP> macro call... I want to include the commas as part of the string
MP> variable but SPSS seems to recognise the comma as a separator for
MP> different tokens.

MP> So my original macro may as below (Shortened for ease of writing,
MP> i.e. just showing two tokens)

MP> DEFINE !VARSCOMMA().
MP> "n_4, n_5, n_6, n_7, n_8, n_9"              -This is the first string I want entered without ""
MP> "n_10, n_11, n_12, n_13, n_14, n_15"        -This is the second
MP> string I want entered without ""
MP> !ENDDEFINE.

MP> I want to input this into the following macro call

MP> DEFINE !METRICS(!POSITIONAL !TOKENS(10)
MP>                 /!POSITIONAL !TOKENS(10)).
MP> !LET !VIN =!1.
MP> !LET !VOU = !2.
MP> !DO !S !IN (!VIN).
MP> LET !VOUT = !HEAD(!VOU).

MP> *OMS.
MP> DATASET DECLARE Ctables.
MP> OMS
MP>  /SELECT TABLES
MP>  /IF COMMANDS = ["CTables"]
MP>      SUBTYPES = ["Custom Table"]
MP>  /DESTINATION FORMAT = SAV NUMBERED = TableNumber_
MP>   OUTFILE = Ctables
MP>   Viewer = NO.
MP> * Custom Tables.
MP> CTABLES
MP>  /VLABELS VARIABLES=ControlGrp !S DISPLAY=DEFAULT  /TABLE !S [COUNT
MP> F40.0] BY ControlGrp  /SLABELS VISIBLE=NO  /CATEGORIES
MP> VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE  /CATEGORIES
MP> VARIABLES=!S [!UNQUOTE(!VOUT)] EMPTY=INCLUDE.
MP> CTABLES
MP>   /VLABELS VARIABLES=ControlGrp exposed DISPLAY=DEFAULT
MP>   /TABLE exposed [COUNT F40.0] BY ControlGrp
MP>   /SLABELS VISIBLE=NO
MP>   /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
MP>   /CATEGORIES VARIABLES=exposed ORDER=A KEY=VALUE EMPTY=EXCLUDE.
MP> OMSEND.

MP> SO the bold line reads
MP>  /CATEGORIES VARIABLES=!S [n_4, n_5, n_6, n_7, n_8, n_9] EMPTY=INCLUDE.

HTH,
 Marta                            mailto:[hidden email]

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

______________________________________________________________________
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
|

Macro tokens problem with commas

Mike P-5
In reply to this post by Mike P-5
Hi All,

I'm still having a problems defining a list which include commas, so far my best efforts have failed, although I have now my latest idea and reasons are detailed underneath I still fail.  If anyone has any suggestions I would be most grateful

Original macro

DEFINE !VARSCOM().
!QUOTE(!CONCAT("n_4, n_5, n_6, n_7, n_8, n_9")))
!QUOTE(!CONCAT("n_10, n_11, n_12, n_13, n_14, n_15"))
!QUOTE(!CONCAT("n_16, n_17, n_18, n_19, n_20, n_21"))
!QUOTE(!CONCAT("n_22, n_23, n_24, n_25, n_26") )
!QUOTE(!CONCAT("n_27, n_28, n_29, n_30, n_31") )
!QUOTE(!CONCAT("n_32, n_33, n_34, n_35, n_36, n_37") )
!QUOTE(!CONCAT("n_39, n_40, n_41, n_42, n_43, n_44, n_45, n_46, n_47"))
!QUOTE(!CONCAT("n_48, n_49, n_50, n_51, n_52, n_53, n_54, n_55, n_56") )
!QUOTE(!CONCAT("n_57, n_58, n_59, n_60, n_61, n_62, n_63, n_64, n_65") )
!QUOTE(!CONCAT("n_66, n_67, n_68, n_69, n_70"))
!ENDDEFINE.

The aim is to create 10 tokens and then to place into another macro.

These 10 tokens being

1.       n_4, n_5, n_6, n_7, n_8, n_9
2.       n_10, n_11, n_12, n_13, n_14, n_15
3.       n_16, n_17, n_18, n_19, n_20, n_21
4.       n_22, n_23, n_24, n_25, n_26
5.       n_27, n_28, n_29, n_30, n_31
6.       n_32, n_33, n_34, n_35, n_36, n_37
7.       n_39, n_40, n_41, n_42, n_43, n_44, n_45, n_46, n_47
8.       n_48, n_49, n_50, n_51, n_52, n_53, n_54, n_55, n_56
9.       n_57, n_58, n_59, n_60, n_61, n_62, n_63, n_64, n_65
10.      n_66, n_67, n_68, n_69, n_70

My reasons for the !Quote !concat fucntions come from the following logic.

!UPCASE(!CONCAT('a,b,c'))  =  A,B,C (So the !concat function would allow me to keep the comma's
!QUOTE('abc') =  abc (So this would allow the macro to be read as 10 single tokens and not 66 different tokens)

My aim would be in my other macro to use the !UNQUOTE function in order to remove the quotation marks

As in
 /CATEGORIES VARIABLES=$Q3 [!UNQUOTE(!VOUT)] EMPTY=INCLUDE.

Where !Vout is the macro I am inserting the variable into

Giving me the following (expanded) line

/CATEGORIES VARIABLES=$Q3 [n_4, n_5, n_6, n_7, n_8, n_9] EMPTY=INCLUDE.


Many thanks in advance

Mike



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marta García-Granero
Sent: 28 June 2006 16:48
To: [hidden email]
Subject: Re: Macro tokens problem with commas

Hi Michael,

Have you tried this MACRO definition? (untested):

DEFINE !METRICS(!POSITIONAL=!CHAREND('/')/!POSITIONAL=!CMDEND).

Then your MACRO call would be:

!METRICS n_4,n_5,n_6,n_7,n_8,n_9 / n_10,n_11,n_12,n_13,n_14,n_15.

MP> I'm currently trying to enter a string of variable into another
MP> macro call... I want to include the commas as part of the string
MP> variable but SPSS seems to recognise the comma as a separator for
MP> different tokens.

MP> So my original macro may as below (Shortened for ease of writing,
MP> i.e. just showing two tokens)

MP> DEFINE !VARSCOMMA().
MP> "n_4, n_5, n_6, n_7, n_8, n_9"              -This is the first string I want entered without ""
MP> "n_10, n_11, n_12, n_13, n_14, n_15"        -This is the second
MP> string I want entered without ""
MP> !ENDDEFINE.

MP> I want to input this into the following macro call

MP> DEFINE !METRICS(!POSITIONAL !TOKENS(10)
MP>                 /!POSITIONAL !TOKENS(10)).
MP> !LET !VIN =!1.
MP> !LET !VOU = !2.
MP> !DO !S !IN (!VIN).
MP> LET !VOUT = !HEAD(!VOU).

MP> *OMS.
MP> DATASET DECLARE Ctables.
MP> OMS
MP>  /SELECT TABLES
MP>  /IF COMMANDS = ["CTables"]
MP>      SUBTYPES = ["Custom Table"]
MP>  /DESTINATION FORMAT = SAV NUMBERED = TableNumber_
MP>   OUTFILE = Ctables
MP>   Viewer = NO.
MP> * Custom Tables.
MP> CTABLES
MP>  /VLABELS VARIABLES=ControlGrp !S DISPLAY=DEFAULT  /TABLE !S [COUNT
MP> F40.0] BY ControlGrp  /SLABELS VISIBLE=NO  /CATEGORIES
MP> VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE  /CATEGORIES
MP> VARIABLES=!S [!UNQUOTE(!VOUT)] EMPTY=INCLUDE.
MP> CTABLES
MP>   /VLABELS VARIABLES=ControlGrp exposed DISPLAY=DEFAULT
MP>   /TABLE exposed [COUNT F40.0] BY ControlGrp
MP>   /SLABELS VISIBLE=NO
MP>   /CATEGORIES VARIABLES=ControlGrp ORDER=A KEY=VALUE EMPTY=INCLUDE
MP>   /CATEGORIES VARIABLES=exposed ORDER=A KEY=VALUE EMPTY=EXCLUDE.
MP> OMSEND.

MP> SO the bold line reads
MP>  /CATEGORIES VARIABLES=!S [n_4, n_5, n_6, n_7, n_8, n_9] EMPTY=INCLUDE.

HTH,
 Marta                            mailto:[hidden email]

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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