"In my data, I have different teams nested within different areas. Right now I have five cities and in each city teams A through E. Some output for each combination of area and team separately should be exported into its own folder. Is there any flexible way to accomplish this?"
SPSS Python Syntax Example
teams = ['A','B','C','D','E']
areas = ['Amsterdam','Zaandam','Utrecht','Den Haag','Enkhuizen']
cases = '\n'.join(['""'.join(['"' + area,team + '"']) for case in range(10) for area in areas for team in teams])
spss.Submit('data list free/area(a9)team(a6).\nbegin data\n%s\nend data.\
*2. Create output folders, generate output and export it into correct output folder for separate groups.
rdir = 'd:/temp/' # Specify root directory for output folders.
splitvars = ['area','team'] # Specify split variables.
vals_0 = set(spss.Cursor([spssaux.VariableDict().VariableIndex(splitvars)])\
vals_1 = set(spss.Cursor([spssaux.VariableDict().VariableIndex(splitvars)])\
for val_0 in[val.rstrip() for val in vals_0]:
for val_1 in [val.rstrip() for val in vals_1]:
ndir = os.path.join(rdir,val_0 + '_' + val_1)
OMS\n/SELECT ALL\n/EXCEPTIF SUBTYPES = ['NOTES']
/DESTINATION FORMAT = HTML OUTFILE ='%s/Output for area = %s, team = %s.htm'
select if %s='%s' and %s='%s'.
- This syntax uses Python so you need to have the SPSS Python Essentials installed for using it.
- The first program block will generate some test data for the actual solution.
- The test data contain two string variables, "team" and "area". Each combination of a team within an area defines a group.
- In the second block, a root directory is specified. This is where the output folders for each group will be created. Their names will contain the team as well as the group so it's easy to see which output it will contain.
- The output for each group will be generated and automatically exported to the correct output folder.
- This solution would need a lot of modifying in order to run it on other data than the test data provided. It's included mainly to illustrate one of several possible approaches to this problem.