Hello again :) I wonder how to use string arguments one by one.id,GROUP,var1,var2,var3,var4,var5 1,1,2,2,2,4,2 2,1,1,3,1,1,2 3,2,4,2,1,1,2 4,1,1,2,1,1,2 5,2,1,2,1,3,2 6,1,1,2,2,1,3 7,1,1,1,2,2,2 8,2,1,1,1,2,2 9,1,1,2,1,2,1 10,2,2,1,1,3,2 11,1,1,2,2,2,1 12,1,1,2,3,2,4 13,1,3,1,2,1,1 14,2,1,3,1,2,2 15,1,1,1,3,1,2 16,2,1,3,1,1,1 17,1,2,3,1,2,3 18,1,2,2,2,1,1 19,2,1,2,1,2,2 20,2,3,1,1,2,1 1) count 2) percent in row 3) percent in column To do this I need to execute 3 commands CROSSTABS /TABLES group by var1 to var5 /CELLS=count. CROSSTABS /TABLES group by var1 to var5 /CELLS=row. CROSSTABS /TABLES group by var1 to var5 /CELLS=column. But I'm looking for faster solution. I tried with macro, like this define !g (t=!CHAREND('/')) CROSSTABS /TABLES group by var1 to var5 /CELLS=!t. !enddefine. !g t=count row column . But in result this 3 arguments are used in the same time, not one by one. How to fix it? Thanks in advance. |
Administrator
|
Use !DO to loop through the list of arguments you hand the macro. See the example below. Note too that I have changed your !CHAREND to !CMDEND, because it makes more sense given the way you call the macro.
*** Start of syntax ***. DEFINE !g (t=!CMDEND) /* Note use of CMDEND */ !DO !arg !IN(!t) /* THIS LINE IS NEW */ CROSSTABS /TABLES group by var1 to var5 /CELLS=!arg. /* NOTE change of argument here. !DOEND /* THIS LINE IS NEW */ !ENDDEFINE. * Call the macro. SET MPRINT ON. !g t=count row column . SET MPRINT OFF. *** End of syntax ***. You can comment out the SET MPRINT lines if you like. But it's a good idea to include them while developing & testing your macro. HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by 88videos
I don’t get why you aren’t doing this: CROSSTABS group by var1 to var5/CELLS=count row column. Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]]
On Behalf Of 88Videoclips . Hello again :) I wonder how to use string arguments one by one. For example. I got simple database. I need to have 3 types of crosstabs, with 2) percent in row 3) percent in column To do this I need to execute 3 commands But I'm looking for faster solution. I tried with macro, like this But in result this 3 arguments are used in the same time, not one by one.
Thanks in advance.
===================== 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
|
In reply to this post by 88videos
You could just forget about the argument and list three crosstabs commands in the macro. But note that you could also do one crosstab with all the cell statistics, double click it to open the pivot table editor, click Pivot > Pivoting Trays and drag the Statistics dimension to the layer. There are options for exporting the layers as separate tables, too. On Mon, Jun 26, 2017 at 12:37 PM, 88Videoclips . <[hidden email]> wrote:
|
In reply to this post by 88videos
I am very impressed how fast I get answers here! Thank you all. Bruce solved my imaginary problem and show how to use properly list of string arguments in macro. Thanks to you I finally understood that. 2017-06-26 20:37 GMT+02:00 88Videoclips . <[hidden email]>:
|
Administrator
|
In reply to this post by Bruce Weaver
And yet another way ;-)
DEFINE !h ( !POS !CMDEND ) !IF (!1 !NE !NULL) !THEN CROSSTABS .../CELLS=!HEAD(!1). !h !TAIL(!1). !IFEND !ENDDEFINE. !h ROW COLUMN TOTAL. Particularily useful technique when you have several lists to process in parallel.
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?" |
Administrator
|
That's neat.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
In reply to this post by 88videos
I have to admit that David's macro is much more difficult to understand. I know basics of using !HEAD and !TAIL, but I can't understand all. Can you (or someone else) give my short explanation how balded elements works and why?:)DEFINE !h ( !POS !CMDEND ) !IF (!1 !NE !NULL) !THEN CROSSTABS /tables group by var1 to var5 /CELLS=!HEAD(!1). !h !TAIL(!1). !IFEND !ENDDEFINE. !h count row column. Thanks in advance. |
Administrator
|
!Head = First token,
!TAIL= All but first token. So the XTABS uses the first token. Macro calls ITSELF with All but the first token. Body runs only if argument is not !Null. Look up Recursion. Here is the thread where this technique was first hatched. http://spssx-discussion.1045642.n5.nabble.com/Recursion-with-Macro-tc5723537.html#a5723549
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?" |
Administrator
|
<EXPLODING HEAD CODE ALERT >
---- DEFINE !a ( !POS !CHAREND ("/") /!POS !CMDEND ) !IF (!HEAD(!2) !NE !NULL) !THEN CROSSTABS TABLES !1 BY !HEAD(!2). !a !1 /!TAIL(!2) !IFEND !ENDDEFINE . DEFINE !b ( !POS !CHAREND ("/") /!POS !CMDEND ) !IF (!HEAD(!2) !NE !NULL) !THEN FREQUENCIES !1 !HEAD(!2). !b !1 /!TAIL(!2) !IFEND !ENDDEFINE . DEFINE !Loop (!POS !CHAREND("/") / !POS !CHAREND ("/") / !POS !CMDEND ) !IF (!HEAD(!2) !NE !NULL) !THEN !CONCAT('!',!1) !HEAD(!2) /!3 . !Loop !1 /!TAIL(!2) /!3 . !IFEND !ENDDEFINE . DEFINE !root ( !POS !CHAREND ("/") / !POS !CHAREND ("/") / !POS !CMDEND ) !IF (!HEAD(!1) !NE !NULL) !THEN !Loop !HEAD(!1) / !2 /!3 . !root !TAIL(!1) / !2 /!3 . !IFEND !ENDDEFINE . DATA LIST FREE / x y z q r s t. BEGIN DATA 1 6 2 3 1 5 3 1 2 3 6 1 3 5 1 2 3 5 6 5 2 END DATA. SET MPRINT ON PRINTBACK ON . !root a b / x y z / q r s t . </EXPLODING HEAD CODE ALERT >
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?" |
Administrator
|
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Administrator
|
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?" |
Free forum by Nabble | Edit this page |