SPSS\Python Code

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

SPSS\Python Code

SUBSCRIBE SPSSX-JohnF
I have this python code (below) which works well, it appends every SPSS file in the directory (annual files).  The files have State data in each. I'd like add a line of code which would append every file together but only, for example, California from each annual file or California and Idaho. Each State is ID'ed by it's fips code, CA=06, ID=16, etc.  Clearly  my experience with Python is very limited, hence my question which I think might be fairly basic, maybe.  

Any help\suggestion, etc. would be appreciated.

begin program.
import spss, spssaux, os, glob

fh = spssaux.FileHandles()

rdir = fh.resolve('StateAnnual_Data')  # Specifies folder containing .sav files.
fils = sorted([fil for fil in os.listdir(rdir) if fil.endswith('.sav')])
spss.Submit('get file "%s/%s".'%(rdir,fils.pop(0)))
for rep in range(len(fils)/49 + 1):
    spss.Submit('add files file=*/%s.'%'/'.join(['file="%s"'%os.path.join(rdir,fil) for fil in fils[49*rep:49*rep + min(49,len(fils)-49*rep)]]))
spss.Submit('exe.')
end program.

dataset name SourceFile.
Cache.

=====================
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: SPSS\Python Code

SUBSCRIBE SPSSX-JohnF
Giving this a bump in hopes of a response.

Thanks.......

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