SPSS Macro Looping

SPSS macros offer the following options for looping.


Ranges

define !per_year(var = !tokens(1)
                /timevar = !tokens(1)
                /start = !tokens(1)
                /end = !tokens(1))
  !DO !y = !start !TO !end !BY 1
    temporary.
    select if !timevar=!y.
    frequencies /variables=!var.
    execute.
  !DOEND
!enddefine

!per_year var=population timevar=year start=2000 end=2008.


Iteration

define !each_year(var = !tokens(1)
                 /timevar = !tokens(1)
                 /years = !cmdend)
  !DO !y !IN (!years)
    temporary.
    select if !timevar=!y.
    frequencies /variables=!var.
    execute.
  !DOEND
!enddefine

!each_year var=population timevar=year years=2000 2002 2008.


CategoryRicottone

SPSS/Macro/Looping (last edited 2023-06-14 15:44:43 by DominicRicottone)