Date: Wed, 2 Feb 2005 07:23:46 -0600
Reply-To: "Peck, Jon" <peck@spss.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Peck, Jon" <peck@spss.com>
Subject: Re: Silly macro question: error when using include for macro
definitions
Content-Type: text/plain; charset="US-ASCII"
While macro is useful in isolating paths and filenames in SPSS syntax, there is also a simpler way, avoiding the use of macro altogether if that is all that is needed.
You can use the FILE HANDLE command to define the file and then just refer to its handle as needed.
For example,
FILE HANDLE fred /NAME='c:\mydata\frederick.sav'.
If you have SPSS 13, you can use this just for the path portion, too. E.g.,
FILE HANDLE fredspath /NAME='c:\mydata'.
GET FILE = 'fredspath\frederick.sav'.
Regards,
Jon Peck
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Raynald Levesque
Sent: Tuesday, February 01, 2005 8:30 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: [SPSSX-L] Silly macro question: error when using include for macro definitions
Hi
You macros are unnecessarily complex. Try the following approach:
define !inpath()'d:\test\'!ENDDEFINE.
define !mrgMeta(dbmeta=!tokens(1) /dtsrf1=!tokens(1) /outfile=!tokens(1))
get translate file=!inpath + !dtsrf1 /type=DBF /keep=filename hitcount .
compute start = len('Article ')+1.
!enddefine
SET MPRINT=YES.
!mrgMeta dbmeta='bz4bmeta1801.txt' dtsrf1='bzRF1.dbf'
outfile='tmp\rawMeta2'.
SET MPRINT=NO.
HTH
Raynald Levesque Raynald@spsstools.net
Visit my SPSS site: http://www.spsstools.net
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
W.H. van Atteveldt
Sent: February 1, 2005 4:38 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Silly macro question: error when using include for macro
definitions
Dear All,
Sorry to bother yet again with a silly macro question. The problem is as
follows:
I have a macro:
define !mrgMeta(dbmeta !tokens(1) / dtsrf1 !tokens(1) / outfile
!tokens(1)) get translate file=!inpath !dtsrf1 /type=DBF /keep=filename
hitcount .
compute start = len('Article ')+1.
...
!enddefine
Where !inpath is an auxilliary macro to join a predefined path to a
filename:
define !inpath(!positional !tokens(1))
!QUOTE(!CONCAT(!UNQUOTE(!eval(!pad)),!UNQUOTE(!eval(!1)))) !ENDDEFINE.
If I manually execute this macro definition and call it there is no
problem.
However, if I save it to a file ('weging.sps') and then include it and
execute is like so:
define !pad() 'd:\test\' !ENDDEFINE.
include 'weging.sps'.
!mrgMeta dbmeta='bz4bmeta1801.txt' dtsrf1='bzRF1.dbf'
outfile='tmp\rawMeta2'.
Something goes wrong with the 'get translate' line: for some reason spss
no longer seems to execute the command and the compute subsequently
fails with a 'there is no working file' error:
!mrgMeta dbmeta='bz4bmeta1801.txt' dtsrf1='bzRF1.dbf'
outfile='tmp\rawMeta2'.
1899 M>
1900 M> .
1901 M> GET TRANSLATE FILE='d:\test\bzRF1.dbf'
1902 M> /TYPE=DBF /KEEP=FILENAME HITCOUNT.
1903 M> COMPUTE START = LEN('Article ')+1.
>Error # 100. Command name: COMPUTE
>This command is not permitted before the beginning of file definition
>commands.
Can someone shed light on the difference between including a syntax file
containing a definition and executing the definition manually? Is there
something I am generally doing wrong about defining and invoking
macro's?
(And the weirdest thing is that, after including the file and trying to
call the macro, if I manualy execute the definition the first time I
call the macro it still fails but the second time it runs without
problem...)
Thanks,
Wouter