Can I remove a macro within a session?

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

Can I remove a macro within a session?

Ruben Geert van den Berg
Dear all,
 
I'm writing a macro but it seems I can't use a name that has already been defined as a macro; I get
 

Error # 6802 in column 1024. Text: (End of Command)

The DEFINE command must begin with the name of the macro being defined.

Something other than a valid macro name was found.

This command not executed.

 
So each time I modify the macro, I append a suffix to it and add the same suffix to the macro call but I find this somewhat inefficient. I'd rather write something like
 
delete !function.
define ! function ()
<blah blah>
!enddefine.
 
!function.


Is there any command to 'UNdefine' a macro in SPSS so I can get rid of the suffixes?
 
TIA!
 
Ruben van den Berg
 





New Windows 7: Simplify what you do everyday. Find the right PC for you.
Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Bruce Weaver
Administrator
Ruben van den Berg wrote
Dear all,

I'm writing a macro but it seems I can't use a name that has already been defined as a macro; I get

Error # 6802 in column 1024. Text: (End of Command)
The DEFINE command must begin with the name of the macro being defined.
Something other than a valid macro name was found.
This command not executed.


So each time I modify the macro, I append a suffix to it and add the same suffix to the macro call but I find this somewhat inefficient. I'd rather write something like
 

delete !function.

define ! function ()

<blah blah>

!enddefine.

!function.

Is there any command to 'UNdefine' a macro in SPSS so I can get rid of the suffixes?


TIA!
Hi Ruben.  This is odd.  I redefine macros all the time without altering the name.  E.g., I make a first draft of the macro, try it  out, and realize I need to revise something, and so on.  My recollection is that in earlier versions of SPSS, I would get a warning message if I defined a macro that was using an already existing macro name, but it allowed me to proceed.  At some point (v15 maybe?) the warning message no longer appeared.  What version are you running?

--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Rick Oliver-3

You should be able to redefine a macro within a session without any problems. As Bruce Weaver notes, a warning used to be issued, but that didn't prevent the macro from changing.

data list free / var1 var2.
begin data
1 2
end data.
set mprint on.
define !mymacro() var1 !enddefine.
freq var=!mymacro.
define !mymacro() var2 !enddefine.
freq var=!mymacro.
set mprint off.


From: Bruce Weaver <[hidden email]>
To: [hidden email]
Date: 12/09/2009 07:50 AM
Subject: Re: Can I remove a macro within a session?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Ruben van den Berg wrote:
>
>
> Dear all,
>
> I'm writing a macro but it seems I can't use a name that has already been
> defined as a macro; I get
>
> Error # 6802 in column 1024. Text: (End of Command)
> The DEFINE command must begin with the name of the macro being defined.
> Something other than a valid macro name was found.
> This command not executed.
>
>
> So each time I modify the macro, I append a suffix to it and add the same
> suffix to the macro call but I find this somewhat inefficient. I'd rather
> write something like
>
>
> delete !function.
>
> define ! function ()
>
> <blah blah>
>
> !enddefine.
>
> !function.
>
> Is there any command to 'UNdefine' a macro in SPSS so I can get rid of the
> suffixes?
>
>
> TIA!
>

Hi Ruben.  This is odd.  I redefine macros all the time without altering the
name.  E.g., I make a first draft of the macro, try it  out, and realize I
need to revise something, and so on.  My recollection is that in earlier
versions of SPSS, I would get a warning message if I defined a macro that
was using an already existing macro name, but it allowed me to proceed.  At
some point (v15 maybe?) the warning message no longer appeared.  What
version are you running?



-----
--
Bruce Weaver
[hidden email]
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.
--
View this message in context:
http://old.nabble.com/Can-I-remove-a-macro-within-a-session--tp26708500p26710320.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


Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Ruben Geert van den Berg
Dear Bruce and Richard,
 
The example below runs fine indeed. I'll have to check my journal file to see exactly which syntax generated these errors and see to what extent I can replicate them. Perhaps something else than defining an existing macro has been the source of all the misery.
 
Thanks a lot for your advice!
 
Ruben 




 



 

Date: Wed, 9 Dec 2009 08:10:30 -0600
From: [hidden email]
Subject: Re: Can I remove a macro within a session?
To: [hidden email]


You should be able to redefine a macro within a session without any problems. As Bruce Weaver notes, a warning used to be issued, but that didn't prevent the macro from changing.

data list free / var1 var2.
begin data
1 2
end data.
set mprint on.
define !mymacro() var1 !enddefine.
freq var=!mymacro.
define !mymacro() var2 !enddefine.
freq var=!mymacro.
set mprint off.


From: Bruce Weaver <[hidden email]>
To: [hidden email]
Date: 12/09/2009 07:50 AM
Subject: Re: Can I remove a macro within a session?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Ruben van den Berg wrote:

>
>
> Dear all,
>
> I'm writing a macro but it seems I can't use a name that has already been
> defined as a macro; I get
>
> Error # 6802 in column 1024. Text: (End of Command)
> The DEFINE command must begin with the name of the macro being defined.
> Something other than a valid macro name was found.
> This command not executed.
>
>
> So each time I modify the macro, I append a suffix to it and add the same
> suffix to the macro call but I find this somewhat inefficient. I'd rather
> write something like
>
>
> delete !function.
>
> define ! function ()
>
> <blah blah>
>
> !enddefine.
>
> !function.
>
> Is there any command to 'UNdefine' a macro in SPSS so I can get rid of the
> suffixes?
>
>
> TIA!
>

Hi Ruben.  This is odd.  I redefine macros all the time without altering the
name.  E.g., I make a first draft of the macro, try it  out, and realize I
need to revise something, and so on.  My recollection is that in earlier
versions of SPSS, I would get a warning message if I defined a macro that
was using an already existing macro name, but it allowed me to proceed.  At
some point (v15 maybe?) the warning message no longer appeared.  What
version are you running?



-----
--
Bruce Weaver
[hidden email]
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.
--
View this message in context:
http://old.nabble.com/Can-I-remove-a-macro-within-a-session--tp26708500p26710320.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




New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Richard Ristow
In reply to this post by Ruben Geert van den Berg
At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro; I get

Error # 6802 in column 1024. Text: (End of Command)
The DEFINE command must begin with the name of the macro being defined.
Something other than a valid macro name was found.
This command not executed.

[when I write]

delete !function.
define ! function ()
<blah blah>
!enddefine.
 
Is the problem in the DEFINE command, with the space between the "!" and the name? I get the message, perhaps version-specific,

Error # 6864 in column 8.  Text: !
The macro name on the DEFINE command is not valid.  If the name begins with !, it must not match the name of a macro command or function, must be no more than 64 characters in length, and must have an alphabetic as its
second character.
This command not executed.

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

Re: Can I remove a macro within a session?

Rick Oliver-3

Yes. If included, the exclamation point is supposed to be part of the macro name (it isn't technically required), and therefore there should be no space between "!" and "function".


From: Richard Ristow <[hidden email]>
To: [hidden email]
Date: 12/09/2009 12:43 PM
Subject: Re: Can I remove a macro within a session?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro; I get

Error # 6802 in column 1024. Text: (End of Command)
The DEFINE command must begin with the name of the macro being defined.
Something other than a valid macro name was found.
This command not executed.


[when I write]

delete !function.
define ! function ()
<blah blah>
!enddefine.

 
Is the problem in the DEFINE command, with the space between the "!" and the name? I get the message, perhaps version-specific,

Error # 6864 in column 8.  Text: !
The macro name on the DEFINE command is not valid.  If the name begins with !, it must not match the name of a macro command or function, must be no more than 64 characters in length, and must have an alphabetic as its
second character.
This command not executed.


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

Re: Can I remove a macro within a session?

Ruben Geert van den Berg
Thank you, but '!function' was just an example. If I add a space between the exclamation point and the macro name, I get a slightly different error than the one I posted:
 
define ! mymacro() var1 !enddefine.
 
>Error # 6864 in column 2. Text: !
>The macro name on the DEFINE command is not valid. If the name begins with
>!, it must not match the name of a macro command or function, must be no
>more than 64 characters in length, and must have an alphabetic as its
>second character.
>This command not executed.

Unfortunately, I've no access to my .jnl file right now but tomorrow I'll try to unravel the mystery.
 
Kind regards,
 
Ruben
 



 



 

Date: Wed, 9 Dec 2009 12:52:08 -0600
From: [hidden email]
Subject: Re: Can I remove a macro within a session?
To: [hidden email]


Yes. If included, the exclamation point is supposed to be part of the macro name (it isn't technically required), and therefore there should be no space between "!" and "function".


From: Richard Ristow <[hidden email]>
To: [hidden email]
Date: 12/09/2009 12:43 PM
Subject: Re: Can I remove a macro within a session?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro; I get

Error # 6802 in column 1024. Text: (End of Command)
The DEFINE command must begin with the name of the macro being defined.
Something other than a valid macro name was found.
This command not executed.


[when I write]

delete !function.
define ! function ()
<blah blah>
!enddefine.

 
Is the problem in the DEFINE command, with the space between the "!" and the name? I get the message, perhaps version-specific,

Error # 6864 in column 8.  Text: !
The macro name on the DEFINE command is not valid.  If the name begins with !, it must not match the name of a macro command or function, must be no more than 64 characters in length, and must have an alphabetic as its
second character.
This command not executed.


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



New Windows 7: Find the right PC for you. Learn more.
CG
Reply | Threaded
Open this post in threaded view
|

Viewer defaults

CG

Is there a way to set default behavior of version 18.0 to mimic Windows settings? I lose the ability to single click, my scroll bars are tiny,  and it is hampering efficiency (and challenging my aging eyes).  Any help appreciated.

 


Confidentiality Notice: This e-mail, including all attachments is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited unless specifically provided under the New Mexico Inspection of Public Records Act. If you are not the intended recipient, please contact the sender and destroy all copies of this message. -- This email has been scanned by the Sybari - Antigen Email System.


emailsignature_html


Confidentiality Notice: This e-mail,including all attachments is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review,use,disclosure or distribution is prohibited unless specifically provided under the New Mexico Inspection of Public Records Act. If you are not the intended recipient, please contact the sender and destroy all copies of this message.
This email has been scanned using Webroot Email Security.


Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Richard Ristow
In reply to this post by Ruben Geert van den Berg
At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro;

As others have noted, this is done all the time with no problem; see Rick Oliver's example, or

define !function ()
ECHO 'First definition of ! function' .
!enddefine.

!function

First definition of ! function

define !function ()
ECHO 'Second definition of ! function' .
!enddefine.

!function.
Second definition of ! function
 
I get  [error message]
 
Error # 6802 in column 1024. Text: (End of Command)

The DEFINE command must begin with the name of the macro being defined.

Something other than a valid macro name was found.

This command not executed.

We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.

We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),

Perhaps something else than defining an existing macro has been the source of all the misery.

Can you reproduce the problem? If so, post both the code and the error message.

-With best wishes,
 Richard
===================== 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
|

Re: Can I remove a macro within a session?

Ruben Geert van den Berg
Dear Richard and others,
 
>We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.
>We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),
>Perhaps something else than defining an existing macro has been the source of all the misery.
 
Probably so. I've been inspecting my journal file and there's many instances of error 6802. Although I obviously don't doubt that I can indeed redefine an existing macro (I've seen the example by Richard Oliver run fine), some instances suggest I can't. I pasted some examples below and although I'm very probably overlooking some minor (or major) detail, I can't figure this out.
 
TIA!!
 
Ruben
 
Redefining already existing macro !readxls5:

def !readxls5()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!lv1.
!let !varlist=!concat(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=sub(!varlist,2)
 add fil !varlist.
datas clo all.
datas nam totaal.
!end.
set mpr off.

 
But the same macro as !readxls6 didn't yield the error:

def !readxls6()
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!lv1.
!let !varlist=!concat(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=sub(!varlist,2)
 add fil !varlist.
datas clo all.
datas nam totaal.
!end.
set mpr on.

 
Even more striking (and I do apologize for posting so much journal file) is this example in which the trouble starts when I define !read_xls for the third rather than the second time.
 
***1, no error.
 
def !read_xls ()
 !do !lv1 =3 !to !9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
*>Error # 6846 in column 17.  Text: !9
*>A macro expression includes an undefined macro variable or a macro operator
*>which is not valid within an expression.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.


***2, no error.
 
def !read_xls ()
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.

 
***3, error.

def !read_xls ()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.

 
***4, new name, no error.

def !readxls ()
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.

 
***5, second attempt new name, error.

def !readxls ()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
datas clo all.
datas nam totaal.
!end.





 



 

Date: Wed, 9 Dec 2009 22:53:44 -0500
From: [hidden email]
Subject: Re: Can I remove a macro within a session?
To: [hidden email]

At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro;

As others have noted, this is done all the time with no problem; see Rick Oliver's example, or

define !function ()
ECHO 'First definition of ! function' .
!enddefine.

!function

First definition of ! function

define !function ()
ECHO 'Second definition of ! function' .
!enddefine.

!function.
Second definition of ! function
 
I get  [error message]
 
Error # 6802 in column 1024. Text: (End of Command)

The DEFINE command must begin with the name of the macro being defined.

Something other than a valid macro name was found.

This command not executed.

We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.

We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),

Perhaps something else than defining an existing macro has been the source of all the misery.

Can you reproduce the problem? If so, post both the code and the error message.

-With best wishes,
 Richard
===================== 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

New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

FW: Can I remove a macro within a session?

Frans Marcelissen-3

I tried it out, and see the same. If i do'n use "define" but "def" the error disappears. Strange!!!!
Frans


Date: Thu, 10 Dec 2009 12:06:57 +0000
From: [hidden email]
Subject: Re: Can I remove a macro within a session?
To: [hidden email]

Dear Richard and others,
 
>We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.
>We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),
>Perhaps something else than defining an existing macro has been the source of all the misery.
 
Probably so. I've been inspecting my journal file and there's many instances of error 6802. Although I obviously don't doubt that I can indeed redefine an existing macro (I've seen the example by Richard Oliver run fine), some instances suggest I can't. I pasted some examples below and although I'm very probably overlooking some minor (or major) detail, I can't figure this out.
 
TIA!!
 
Ruben
 
Redefining already existing macro !readxls5:

def !readxls5()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!lv1.
!let !varlist=!concat(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=sub(!varlist,2)
 add fil !varlist.
datas clo all.
datas nam totaal.
!end.
set mpr off.

 
But the same macro as !readxls6 didn't yield the error:

def !readxls6()
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!lv1.
!let !varlist=!concat(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=sub(!varlist,2)
 add fil !varlist.
datas clo all.
datas nam totaal.
!end.
set mpr on.

 
Even more striking (and I do apologize for posting so much journal file) is this example in which the trouble starts when I define !read_xls for the third rather than the second time.
 
***1, no error.
 
def !read_xls ()
 !do !lv1 =3 !to !9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
*>Error # 6846 in column 17.  Text: !9
*>A macro expression includes an undefined macro variable or a macro operator
*>which is not valid within an expression.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.


***2, no error.
 
def !read_xls ()
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.

 
***3, error.

def !read_xls ()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.

 
***4, new name, no error.

def !readxls ()
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
!end.

 
***5, second attempt new name, error.

def !readxls ()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
 !do !lv1 =3 !to 9
 get data
 /type=xls
 /file=' Business respons 2009.xls'
 /sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
 !doend
 !let !varlist=!sub(!varlist,2)
 add fil !varlist.
datas clo all.
datas nam totaal.
!end.





 



 

Date: Wed, 9 Dec 2009 22:53:44 -0500
From: [hidden email]
Subject: Re: Can I remove a macro within a session?
To: [hidden email]

At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro;

As others have noted, this is done all the time with no problem; see Rick Oliver's example, or

define !function ()
ECHO 'First definition of ! function' .
!enddefine.

!function

First definition of ! function

define !function ()
ECHO 'Second definition of ! function' .
!enddefine.

!function.
Second definition of ! function
 
I get  [error message]
 
Error # 6802 in column 1024. Text: (End of Command)

The DEFINE command must begin with the name of the macro being defined.

Something other than a valid macro name was found.

This command not executed.

We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.

We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),

Perhaps something else than defining an existing macro has been the source of all the misery.

Can you reproduce the problem? If so, post both the code and the error message.

-With best wishes,
 Richard
===================== 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

New Windows 7: Find the right PC for you. Learn more.

De nieuwe Internet Explorer: sneller, eenvoudiger en veiliger dan ooit Download nu

Minder SPAM in de verbeterde Windows Live Hotmail
Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Jon K Peck
In reply to this post by Ruben Geert van den Berg

It appears to me that when you write
def !read_xls ()
the macro is being expanded rather than redefined, hence the trouble.
If you write
define !read_xls()
then repeated redefinitions seem to work properly (once you correct the !9 in the !DO).

So don't abbreviate DEFINE.

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: Ruben van den Berg <[hidden email]>
To: [hidden email]
Date: 12/10/2009 05:09 AM
Subject: Re: [SPSSX-L] Can I remove a macro within a session?
Sent by: "SPSSX(r) Discussion" <[hidden email]>





Dear Richard and others,

>We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.
>We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),
>Perhaps something else than defining an existing macro has been the source of all the misery.

Probably so. I've been inspecting my journal file and there's many instances of error 6802. Although I obviously don't doubt that I can indeed redefine an existing macro (I've seen the example by Richard Oliver run fine), some instances suggest I can't. I pasted some examples below and although I'm very probably overlooking some minor (or major) detail, I can't figure this out.

TIA!!

Ruben

Redefining already existing macro !readxls5:

def !readxls5()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
!do !lv1 =3 !to 9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!lv1.
!let !varlist=!concat(!varlist,'/fil data',!lv1)
!doend
!let !varlist=sub(!varlist,2)
add fil !varlist.
datas clo all.
datas nam totaal.
!end.
set mpr off.


But the same macro as !readxls6 didn't yield the error:

def !readxls6()
!do !lv1 =3 !to 9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!lv1.
!let !varlist=!concat(!varlist,'/fil data',!lv1)
!doend
!let !varlist=sub(!varlist,2)
add fil !varlist.
datas clo all.
datas nam totaal.
!end.
set mpr on.


Even more striking (and I do apologize for posting so much journal file) is this example in which the trouble starts when I define !read_xls for the third rather than the second time.

***1, no error.

def !read_xls ()
!do !lv1 =3 !to !9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
*>Error # 6846 in column 17.  Text: !9
*>A macro expression includes an undefined macro variable or a macro operator
*>which is not valid within an expression.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
!doend
!let !varlist=!sub(!varlist,2)
add fil !varlist.
!end.


***2, no error.

def !read_xls ()
!do !lv1 =3 !to 9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
!doend
!let !varlist=!sub(!varlist,2)
add fil !varlist.
!end.


***3, error.

def !read_xls ()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
!do !lv1 =3 !to 9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
!doend
!let !varlist=!sub(!varlist,2)
add fil !varlist.
!end.


***4, new name, no error.

def !readxls ()
!do !lv1 =3 !to 9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
!doend
!let !varlist=!sub(!varlist,2)
add fil !varlist.
!end.


***5, second attempt new name, error.

def !readxls ()
*>Error # 6802 in column 1024.  Text: (End of Command)
*>The DEFINE command must begin with the name of the macro being defined.
*>Something other than a valid macro name was found.
*>Error # 6807 in column 1.  Text: get
*>The DEFINE command does not include parameter definitions within parentheses.
*>The lack of any parameters must be indicated by a set of parentheses following
*>the macro name.
!do !lv1 =3 !to 9
get data
/type=xls
/file=' Business respons 2009.xls'
/sheet=index !lv1.
datas nam !con('data',!lv1).
comp month=!vl1.
!let !varlist=!con(!varlist,'/fil data',!lv1)
!doend
!let !varlist=!sub(!varlist,2)
add fil !varlist.
datas clo all.
datas nam totaal.
!end.











Date: Wed, 9 Dec 2009 22:53:44 -0500
From: [hidden email]
Subject: Re: Can I remove a macro within a session?
To: [hidden email]

At 06:02 AM 12/9/2009, Ruben van den Berg wrote:

I'm writing a macro but it seems I can't use a name that has already been defined as a macro;

As others have noted, this is done all the time with no problem; see Rick Oliver's example, or

define !function ()
ECHO 'First definition of ! function' .
!enddefine.

!function

First definition of ! function

define !function ()
ECHO 'Second definition of ! function' .
!enddefine.

!function.
Second definition of ! function


I get  [error message]

Error # 6802 in column 1024. Text: (End of Command)

The DEFINE command must begin with the name of the macro being defined.

Something other than a valid macro name was found.

This command not executed.


We should have called you on this a while back: if you ask for help with an error message, always post the code that produced it.

We've been following your belief that the problem was re-defining an existing macro, when, as you later wrote (and we should have thought of),

Perhaps something else than defining an existing macro has been the source of all the misery.

Can you reproduce the problem? If so, post both the code and the error message.

-With best wishes,
Richard
===================== 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

New Windows 7: Find the right PC for you. Learn more.

Reply | Threaded
Open this post in threaded view
|

Re: Can I remove a macro within a session?

Richard Ristow
In reply to this post by Ruben Geert van den Berg
Dear Ruben,

At 07:06 AM 12/10/2009, you wrote:

>I do apologize for posting so much journal file) is this example in
>which the trouble starts when I define !read_xls for the third
>rather than the second time.

The apology is most thoroughly NOT needed. On a very quick glance, it
looks like all that you've posted is relevant, and it seems to
already be attracting useful responses.

(And what SPSS is doing does seem strange, but that's for other
responders, or for me after looking at it much harder.)

-With best regards,
  Richard

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

Re: Can I remove a macro within a session?

Ruben Geert van den Berg
Dear Richard, Catherine and others,

Jon Peck suggested that writing 'define' instead of 'def' should solve the trouble. I've been working on a new macro yesterday, I followed this advice and -indeed!- the problem didn't occur. Once again: thanks a lot, Jon!

However, if one attempts to abbreviate a command excessively, SPSS will usually not carry out anything but rather warn that the command is not recognized and you may have tried to abbreviate it excessively. So, strictly, I think SPSS should either a) read 'def' as 'define' or b) not to anything but issue the aforementioned warning. SPSS' preference for some unknown plan c) doesn't really matter for the practical purposes with which I'm concerned.

Thanks to all who contributed, it's appreciated!

Ruben
 




> Date: Fri, 11 Dec 2009 15:20:50 -0500
> From: [hidden email]
> Subject: Re: Can I remove a macro within a session?
> To: [hidden email]
>
> Dear Ruben,
>
> At 07:06 AM 12/10/2009, you wrote:
>
> >I do apologize for posting so much journal file) is this example in
> >which the trouble starts when I define !read_xls for the third
> >rather than the second time.
>
> The apology is most thoroughly NOT needed. On a very quick glance, it
> looks like all that you've posted is relevant, and it seems to
> already be attracting useful responses.
>
> (And what SPSS is doing does seem strange, but that's for other
> responders, or for me after looking at it much harder.)
>
> -With best regards,
> Richard
>
> =====================
> 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


New Windows 7: Simplify what you do everyday. Find the right PC for you.