Calculations With Macro Variables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * How to do arithmetic with macro variables. * Posted to SPSSX-L on 1999/09/24 by Rolf Kjoeller <rolf.kjoeller@GET2NET.DK>. /* The question was: Is it possible to perform calculations on macro variables ? Eg. I would like to have a macro which reads a macro variable Year, but given Year I would like to calculate the year '15 years before Year'. */. *** Method 1. define !subtrct (year=!tokens(1) /minus=!tokens(1)) . preserve . set printback=on mprint=on errors = off . /******** BEGIN INTERESTING PART *** !let !x = !length(!concat(!blanks(!minus)," ")) !let !newyear = !length(!substr(!blanks(!year),!x)) . /******** END INTERESTING PART *** compute tst = !newyear . restore . !enddefine . !subtrct year=1999 minus=15 . !subtrct year=1984 minus=25 . /* WATCH OUT. !subtrct year=1999 minus=2000 . *** Method 2. define !sub2 (year=!tokens(1) /minus=!tokens(1)) . COMPUTE tst=!year-!minus. EXE. !enddefine. !sub2 year=1999 minus=15 . !sub2 year=1984 minus=25 . /* WATCH OUT. !sub2 year=1999 minus=2000 . |
Related pages
...