|
Hello, |
|
Hi Shane,
I try to make the Macro as simple as possible with just 1 variable per run. Please note that I cannot test out this macro due to the fact that I do not have your data file and this Ctable looks complex for me to churn out a dummy one. So please test this out over at your side. The macro will need to be run in order for !dowork to work whenever you start a new session of SPSS. Regards Dorraj Oet define !dowork (!positional !token(1)). CTABLES /VLABELS VARIABLES=!1 DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE !1 [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=!1 [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. !enddefine. !dowork Q3a. !dowork Q3b. !dowork Q3c. Date: Mon, 7 Jun 2010 15:13:19 -0400 From: [hidden email] Subject: CTABLES Macro To: [hidden email] Hello, I have the following syntax I need to run on several variables (i.e., Q3a, Q3b, Q3c, etc.). I have tried writing a macro to perform such a task, but I have not yet had any luck. Any assistance would be much appreciated! CTABLES /VLABELS VARIABLES=Q3c DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE Q3c [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=Q3c [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. Thank you in advance. Shane Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now. |
|
Hi
Shane,
You
can run several variables by using the syntax from Dorraj with a small
improvement:
define dowork (!positional
!token(1)).
CTABLES /VLABELS VARIABLES=!1 DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE !1 [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=!1 [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. !enddefine. DEFINE num (!POS !cmdend). !DO !i !IN (!1). DOWORK !i. !DOEND. !ENDDEFINE. num Q3a Q3b Q3c
etc.
Regards,
Gerard Volker
Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens DorraJ Oet Verzonden: dinsdag 8 juni 2010 5:48 Aan: [hidden email] Onderwerp: Re: CTABLES Macro I try to make the Macro as simple as possible with just 1 variable per run. Please note that I cannot test out this macro due to the fact that I do not have your data file and this Ctable looks complex for me to churn out a dummy one. So please test this out over at your side. The macro will need to be run in order for !dowork to work whenever you start a new session of SPSS. Regards Dorraj Oet define !dowork (!positional !token(1)). CTABLES /VLABELS VARIABLES=!1 DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE !1 [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=!1 [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. !enddefine. !dowork Q3a. !dowork Q3b. !dowork Q3c. Date: Mon, 7 Jun 2010 15:13:19 -0400 From: [hidden email] Subject: CTABLES Macro To: [hidden email] Hello, I have the following syntax I need to run on several variables (i.e., Q3a, Q3b, Q3c, etc.). I have tried writing a macro to perform such a task, but I have not yet had any luck. Any assistance would be much appreciated! CTABLES /VLABELS VARIABLES=Q3c DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE Q3c [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=Q3c [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. Thank you in advance. Shane ! Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now. |
|
In reply to this post by Shane S Allua
Here's a Python solution: begin program python. import spss varlist=['Q3a', 'Q3b', Q3c'] for var in varlist: spss.Submit(""" CTABLES /VLABELS VARIABLES=%(var)s DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE Q3c [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=%(var)s [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. """ %locals()) end program.
Hello, I have the following syntax I need to run on several variables (i.e., Q3a, Q3b, Q3c, etc.). I have tried writing a macro to perform such a task, but I have not yet had any luck. Any assistance would be much appreciated! CTABLES /VLABELS VARIABLES=Q3c DISPLAY=NONE /PCOMPUTE &cat1 = EXPR([1] + [2]) /PPROPERTIES &cat1 LABEL = "Favorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat2 = EXPR([3]) /PPROPERTIES &cat2 LABEL = "Neutral" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /PCOMPUTE &cat3 = EXPR([4] + [5]) /PPROPERTIES &cat3 LABEL = "Unfavorable" FORMAT=LAYERPCT.VALIDN 'Percentage' PCT40.1 HIDESOURCECATS=NO /TABLE Q3c [C][LAYERPCT.VALIDN 'Percentage' PCT40.1] /CATEGORIES VARIABLES=Q3c [&cat1, &cat2, &cat3, 1, 2, 3, 4, 5] EMPTY=INCLUDE /TITLES CORNER='Description of survey item'. Thank you in advance. Shane |
| Free forum by Nabble | Edit this page |
