List of string arguments in macro. How to use them NOT at once?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

List of string arguments in macro. How to use them NOT at once?

88videos
Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.



Wolny od wirusów. www.avast.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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

Bruce Weaver
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.

88videos wrote
Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Wolny
od wirusów. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

Maguin, Eugene
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 .
Sent: Monday, June 26, 2017 2:37 PM
To: [hidden email]
Subject: List of string arguments in macro. How to use them NOT at once?

 

Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.

 

 

Wolny od wirusów. www.avast.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

===================== 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

Jon Peck
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:
Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.



Wolny od wirusów. www.avast.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



--
Jon K Peck
[hidden email]

===================== 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

88videos
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]>:
Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.



Wolny od wirusów. www.avast.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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

David Marso
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.


Bruce Weaver wrote
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.

88videos wrote
Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Wolny
od wirusów. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

=====================
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
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
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

Bruce Weaver
Administrator
That's neat.  

David Marso wrote
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.


Bruce Weaver wrote
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.

88videos wrote
Hello again :)

I wonder how to use string arguments one by one.

For example. I got simple database.

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

I need to have 3 types of crosstabs, with
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.



<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Wolny
od wirusów. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

88videos
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.



===================== 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

David Marso
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

88videos wrote
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.

=====================
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
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
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

David Marso
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 >

David Marso wrote
!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

88videos wrote
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.

=====================
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
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
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

Bruce Weaver
Administrator


David Marso wrote
<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 >

David Marso wrote
!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

88videos wrote
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.

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List of string arguments in macro. How to use them NOT at once?

David Marso
Administrator


Bruce Weaver wrote


David Marso wrote
<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 >

David Marso wrote
!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

88videos wrote
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.

=====================
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
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?"
Loading...