Elyse Cottrell-Martin
2019-06-05 20:31:01 UTC
I have a lag sequence that I would like to make into a macro since I am potentially going to be using it on about 12 different variables.
This is an example of the syntax I want to make a macro:
COMPUTE var_lag = lag(var).
EXECUTE.
formats var_lag(f5.0).
DO IF (AssessType=0).
RECODE var_lag (ELSE=999).
END IF.
EXECUTE.
RECODE var_lag (999=SYSMIS).
EXECUTE.
I have looked all over the internet but am not clear if I can even do it (I would need to set "var" in the above syntax as something I can define,
So if I say var = Assess4 it would run it as:
COMPUTE Assess4_lag = lag(Assess4 ).
EXECUTE.
formats Assess4_lag(f5.0).
DO IF (AssessType=0).
RECODE Assess4_lag (ELSE=999).
END IF.
EXECUTE.
RECODE Assess4_lag (999=SYSMIS).
EXECUTE.
I tried the following:
****.
DEFINE lagging (var = !cmdend)
COMPUTE var_lag = lag(var).
EXECUTE.
formats var_lag(f5.0).
DO IF (AssessType=0).
RECODE var_lag (ELSE=999).
END IF.
EXECUTE.
RECODE var_lag (999=SYSMIS).
EXECUTE.
!ENDDEFINE.
lagging var = Assess4
****.
But I get a whole bunch of errors (Basically anywhere the var is). I've tried it with !var and !cmdend and I just get the same errors.
This is my first time using Macros (and I just started learning syntax a few weeks ago, although I've used SPSS for a few years). Any help is appreciated.
This is an example of the syntax I want to make a macro:
COMPUTE var_lag = lag(var).
EXECUTE.
formats var_lag(f5.0).
DO IF (AssessType=0).
RECODE var_lag (ELSE=999).
END IF.
EXECUTE.
RECODE var_lag (999=SYSMIS).
EXECUTE.
I have looked all over the internet but am not clear if I can even do it (I would need to set "var" in the above syntax as something I can define,
So if I say var = Assess4 it would run it as:
COMPUTE Assess4_lag = lag(Assess4 ).
EXECUTE.
formats Assess4_lag(f5.0).
DO IF (AssessType=0).
RECODE Assess4_lag (ELSE=999).
END IF.
EXECUTE.
RECODE Assess4_lag (999=SYSMIS).
EXECUTE.
I tried the following:
****.
DEFINE lagging (var = !cmdend)
COMPUTE var_lag = lag(var).
EXECUTE.
formats var_lag(f5.0).
DO IF (AssessType=0).
RECODE var_lag (ELSE=999).
END IF.
EXECUTE.
RECODE var_lag (999=SYSMIS).
EXECUTE.
!ENDDEFINE.
lagging var = Assess4
****.
But I get a whole bunch of errors (Basically anywhere the var is). I've tried it with !var and !cmdend and I just get the same errors.
This is my first time using Macros (and I just started learning syntax a few weeks ago, although I've used SPSS for a few years). Any help is appreciated.