Still having trouble figuring this out. I would like a non-Python approach if possible, but even the Python code you show assumes the values are stored in the file (in your case, school). In my case, they are not - they are specified at run time and may expand over time (e.g., 2009 to 2013). And all of the !DO ... !TO examples I find focus on looping through a set of *variables*, but not values.
I've attached a sample dataset to help illustrate. The data look like:
Code: Select all
SchoolID YrEnrolled SubjectID Sex
1 10/01/2009 1 Female
1 10/01/2009 2 Male
1 10/01/2010 3 Male
The code below works well. For each year I define (e.g., 2009, 2010, and 2011), the syntax will create an SPSS file showing the percentage of males and females in each schoool, for the given year. The problem is that it requires manually replacing the values for YYYY and YYstr and then rerunning the code. My goal is to have it automatically loop through a list of a values defined at run time (e.g., 2009 to 2011, and "09", "10", and "11").
Code: Select all
* Define the FFY.
define YYYY () 2012 !enddefine.
define YYstr ( ) "12" !enddefine.
* Run some code.
compute FFY = date.mdy(10,01,YYYY-1).
formats FFY (ADate10).
oms select tables
/destination format = sav outfile = "C:\temp\Period " +YYstr+".sav"
/if commands = ['ctables'] subtypes = ['Custom Table'].
select if FFY=YrEnrolled.
/VLABELS VARIABLES=SchoolID Sex DISPLAY=BOTH
/TABLE SchoolID [C][ROWPCT.COUNT PCT40.1] BY Sex [C]
/CATEGORIES VARIABLES=SchoolID ORDER=A KEY=VALUE EMPTY=EXCLUDE TOTAL=YES POSITION=AFTER
/CATEGORIES VARIABLES=Sex ORDER=A KEY=VALUE EMPTY=INCLUDE.
I've tried all sorts of DO REPEAT and DO! !TO options and they all bomb. The syntax is tricky to figure out. Thanks again for any pointers.
You do not have the required permissions to view the files attached to this post.