ADD FILE macro: re-assigning macro variables inside loop

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

ADD FILE macro: re-assigning macro variables inside loop

M-24
Hi - The macro below should run ADD FILES over files listed in !fileList.
 
It doesn't work: I get a series of
--------------
Error # 1. Command name: /
The first word in the line is not recognized as an SPSS Statistics command.
This command not executed.
--------------
 
I know the command termination period is missing in the macro (I'm assuming the a blank line after the last / FILE =  will take care of that). Adding a period below !DOEND doesn't seem like the right thing to do.
 
The !first declaration is there to differentiate between ADD FILES FILE =  and the subsequent / FILE = statements .
 
There are less than 50 files in !fileList, and they're all in c:\temp. The file names have spaces, so are quoted in !fileList.
 
I've adapted Bruce Weaver's !addfile macro (www.spsstools.net) to get the job done, and that works fine. However, could you help me figure out what's wrong with the code below? Thanks.
 
Marc.
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DEFINE !consolidate(!pos !charend('/'))
!LET !first  = 1
!DO !var !IN (!1)
* ------------------------------ .
!LET !filename = !UNQUOTE(!var)
!IF (!first = 1) !THEN
NEW FILE.
ADD FILES FILE = !QUOTE(!CONCAT('C:\temp\', !filename, '.sav'))
!LET !first = 0
!ELSE
        / FILE = !QUOTE(!CONCAT('C:\temp\', !filename, '.sav'))
!IFEND
* ------------------------------ .
!DOEND.
 
SAVE OUTFILE = 'C:\temp\feb.sav'.
!ENDDEFINE.

!consolidate !fileList /.
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Express your personality in color! Preview and select themes for HotmailĀ®. See how.
Reply | Threaded
Open this post in threaded view
|

Re: ADD FILE macro: re-assigning macro variables inside loop

Albert-Jan Roskam
Hi!

Untested:

DEFINE !consolidate(!filename !cmdend)
!LET !first  = 1.
!DO !var !IN (!filename)
* ------------------------------ .
!IF (!first = 1) !THEN
save outfile = 'c:/temp/feb.sav'.
!LET !first = 0.
!ELSE
ADD FILES /FILE = * /FILE = !filename.
!IFEND
* ------------------------------ .
!DOEND.
SAVE OUTFILE = 'c:\temp\feb.sav'.
!ENDDEFINE.

!consolidate 'd:/temp/file1.sav' 'd:/temp/file3.sav' 'd:/temp/file3.sav'.

Cheers!!
Albert-Jan


--- On Tue, 3/24/09, M <[hidden email]> wrote:

> From: M <[hidden email]>
> Subject: ADD FILE macro: re-assigning macro variables inside loop
> To: [hidden email]
> Date: Tuesday, March 24, 2009, 5:05 PM
>
>
>
> #yiv1319603514 .hmmessage P
> {
> margin:0px;padding:0px;}
> #yiv1319603514 {
> font-size:10pt;font-family:Verdana;}
>
>
>
> Hi - The macro below should run ADD FILES over files listed
> in !fileList.
>
>
>
> It doesn't work: I get a series of
>
> --------------
>
> Error # 1. Command name: /
>
> The first word in the line is not recognized as an SPSS
> Statistics command.
>
> This command not executed.
>
> --------------
>
>
>
> I know the command termination period is missing in the
> macro (I'm assuming the a blank line after the last /
> FILE =  will take care of that). Adding a
> period below !DOEND doesn't seem like the right
> thing to do.
>
>
>
> The !first declaration is there to differentiate between
> ADD FILES FILE =  and the subsequent / FILE =
> statements .
>
>
>
> There are less than 50 files in !fileList, and they're
> all in c:\temp. The file names have spaces, so are
> quoted in !fileList.
>
>
>
> I've adapted Bruce Weaver's !addfile macro (www.spsstools.net) to
> get the job done, and that works fine. However, could you
> help me figure out what's wrong with the code below?
> Thanks.
>
>
>
> Marc.
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> DEFINE !consolidate(!pos !charend('/'))
>
> !LET !first  = 1
>
> !DO !var !IN (!1)
> * ------------------------------ .
> !LET !filename = !UNQUOTE(!var)
>
> !IF (!first = 1) !THEN
>
> NEW FILE.
> ADD FILES FILE = !QUOTE(!CONCAT('C:\temp\',
> !filename, '.sav'))
> !LET !first = 0
>
> !ELSE
>
>         / FILE =
> !QUOTE(!CONCAT('C:\temp\', !filename,
> '.sav'))
>
> !IFEND
>
> * ------------------------------ .
> !DOEND.
>
>
>
> SAVE OUTFILE = 'C:\temp\feb.sav'.
>
> !ENDDEFINE.
>
>
> !consolidate !fileList /.
>
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Express your personality in color! Preview and
> select themes for HotmailĀ®. See
> how.
>

=====================
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: ADD FILE macro: re-assigning macro variables inside loop

Richard Ristow
In reply to this post by M-24
At 12:05 PM 3/24/2009, M wrote:

>Hi - The macro below should run ADD FILES over files listed in
>!fileList. It doesn't work. [Error messages suppressed]

When a macro's doing something mysterious, it's always good to run it
with MPRINT set ON. You ran,

!consolidate !fileList /.

Try

PRESERVE.
SET MPRINT ON.
!consolidate !fileList /.
RESTORE.

("PRESERVE" and "RESTORE" are used so you won't make a permanent
change to the setting.)

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