Date: Wed, 20 Aug 2008 02:51:04 -0700
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Albert-jan Roskam <email@example.com>
Subject: Re: Script/Macro/Syntax Help
Content-Type: text/plain; charset=us-ascii
This is similar to some problem posted earlier this week. See the code below. One general question re: python:
why is 'savlist' composed of elements of the form:
....whereas 'savlist[i]' generates something like
Notice the single backslash. How can I prevent this? I tried several options mentioned in os.path, but without result.
savlist = glob.glob("d:/temp/*.sav")
for i in range(len(savlist)):
spss.Submit(""" get file = '%s'.
insert file = 'c:/example/recode.sps'.
save outfile = '%s_r.sav.'
""" % (savlist[i], savlist[i][:-4]))
print "Nothing to do"
--- On Tue, 8/19/08, Craig Johnson <firstname.lastname@example.org> wrote:
> From: Craig Johnson <email@example.com>
> Subject: Script/Macro/Syntax Help
> To: SPSSX-L@LISTSERV.UGA.EDU
> Date: Tuesday, August 19, 2008, 7:59 PM
> I am looking to create a script/macro/syntax to help me with
> some analyses.
> In essence, I need to open a series of files, run syntax on
> each file, and
> then save the altered file as FileName_R.sav. For example
> say I have files
> 1.sav, 2.sav, and 3.sav in the folder C:/example/ and want
> to run a recode
> on all the files using the following syntax file
> C:/example/syntax/recode.sps. The code needs to open up
> 1.sav, run
> recode.sps, and then save the recoded file to 1_r.sav in
> It would then open 2.sav, run recode.sps, and save the
> recoded file. Finally,
> it would open 3.sav, run recode.sps, and then save the
> recoded file.
> The catch here is that the code needs to be generic so that
> it works on all
> the files in the folder. (Sorry merging them all together
> isn't an
> option). For example, the next time I run the syntax
> folder C:/example/ may
> include 4.sav, 5.sav, and 6.sav so the code needs to
> account for that.
> Any ideas on how to accomplish this using some sort of
> generic code?
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@LISTSERV.UGA.EDU (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
> INFO REFCARD
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
For a list of commands to manage subscriptions, send the command