Automated production of unique saved files

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

Automated production of unique saved files

Marsha and Mike SZYMCZUK
Can SPSS produce unique and clearly defined files?
 
I have 60 buildings that require a unique file title; so that a building administrator may easily retrieve his/her own report SPSS report.
 
In my database, one of the fields has the name for each building such as, James Madison High School.
 
I would like to automate a process by which SPSS sorts a file, on building name, processes the information for each building and produces a unique file (i.e. 60 files) with the building name as part of the SAVE file.
 
I know in SPSS 11.5 the ")SPLIT" command in Report can produce a unique title for each report.  Is there a parallel in the SAVE command ?
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Automated production of unique saved files

Albert-Jan Roskam

Hi!

 

Something like this may do what you want. I builds a Python list of all the building names, then applies those names to select & save the appropriate records using the building names.

The XSAVE (as opposed to SAVE) intends to speed up things, but every 10 xsaves an EXE is issued (as 10 is the limit of xsave). I added a numerical prefix to file name, and also replaced

spaces with underscores. That's because I loathe file names with lower/uppercase and spaces ;-))

 

Cheers!!

Albert-Jan

 

* sample data.
data list free / building (a20).
begin data
'eiffel tower'
'statue of liberty'
'sears tower'
'big ben'
'petronas towers'
end data.
compute some_var = rv.uniform(0, 1).
save outfile = 'd:/temp/workfile.sav'.


* actual code.
set mprint = on.
begin program.
import spss
spss.Submit("""get file = 'd:/temp/workfile.sav' / keep = building.
aggr out = * / break = building / n = n.""")
dataCursor = spss.Cursor([0])
fns = [dataCursor.fetchone()[0].strip() for case in range(spss.GetCaseCount())]
dataCursor.close()
spss.Submit("get file = 'd:/temp/workfile.sav'.")
for k, fn in enumerate(fns):
    building = fn.replace(" ", "_").lower()
    spss.Submit("do if (building = '%s')." % fn)
    spss.Submit("xsave outfile = 'd:/temp/%02d_%s.sav'." % ((k + 1), building))
    spss.Submit("end if.")
    if (k + 1) % 10 == 0: spss.Submit("exe.")  
spss.Submit("exe.")
end program.




From: Marsha and Mike SZYMCZUK <[hidden email]>
To: [hidden email]
Sent: Tuesday, February 10, 2009 2:24:51 PM
Subject: Automated production of unique saved files

Can SPSS produce unique and clearly defined files?
 
I have 60 buildings that require a unique file title; so that a building administrator may easily retrieve his/her own report SPSS report.
 
In my database, one of the fields has the name for each building such as, James Madison High School.
 
I would like to automate a process by which SPSS sorts a file, on building name, processes the information for each building and produces a unique file (i.e. 60 files) with the building name as part of the SAVE file.
 
I know in SPSS 11.5 the ")SPLIT" command in Report can produce a unique title for each report.  Is there a parallel in the SAVE command ?