* How to do arithmetic with macro variables. * Posted to SPSSX-L on 1999/09/24 by Rolf Kjoeller . /* 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 .