Hoping for some Python magic for this ...
I currently have syntax that requires the user to first specify a year (e.g., 2010), the last digits of the year as a string (e.g., "10"), and either an "A" or "B." For example: define YYYY () 2010 !enddefine. define YYstr () "10" !enddefine. define PeriodType () "A" !enddefine. The year value is used in some date calculations (e.g., date.mdy(10,01,YYYY-1). The string values are used to create a string variable (e.g., "10A"), to determine how to calculate some things later in the syntax (e.g., if "A", then do this, if "B", then do this), and to create unique file names (e.g., MyFile_' + YYstr + PeriodType + '.sav'). Typically, the syntax needs to be run for multiple years and A & B combinations. For example, the user will know at the start that he needs to the run the syntax for 10A through 14B. In other words: 10A, 10B, 11A, 11B, 12A, 12B, 13A, 13B, 14A, 14B Is there a way for the user to enter the start and end parameters (e.g., "10A" and "14B") and have the syntax loop through these so it runs for each combination? I'm thinking something like: define StartPeriod () "10A" !enddefine. define EndPeriod () "14B" !enddefine. If that's too tricky, maybe: define StartYear () 2010 !enddefine. define StartPeriod () "A" !enddefine. define EndYear () 2014 !enddefine. define EndPeriod () "B" !enddefine. Thank you for any starting pointers for how to tackle this. |
I don't have time to look at this to setup a demo but you don't need the start and end points as quoted strings for starters (you can have them quoted in the macro itself - add leading zero also ect). You can then have the 10 and 14 as numeric values as arguments for your start and end parameters. Then you can have bundles of fun wrapping your head around doing basic additional arithmetic in SPSS macro language: http://pages.infinit.net/rlevesqu/Macros/ArithmeticWithMacroVariables.txt That should give you enough clues, basically your creating a counter starting from 10, adding one each time and then stopping when it equals 14 and you do all this by building a string of blanks and evaluating its length (i.e. the number of blanks) - again referring to the link shared. And yes python magic is definitely the way forward! begin program. for year in xrange(2010,2014+1): for period in ["A","B"]: print year, period end program On 14 May 2015 at 08:26, Fiveja <[hidden email]> wrote: Hoping for some Python magic for this ... |
Free forum by Nabble | Edit this page |