Created
March 7, 2017 21:17
-
-
Save statgeek/cb52f1a54868e959a838f2b6f3dfad20 to your computer and use it in GitHub Desktop.
SAS Macro to create lagged time series data for variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro lag(vars, lags); | |
%let m = %sysfunc(countw(&vars)); | |
%do i=1 %to &m; | |
%let var = %scan(&vars,&i); | |
%do j=1 %to &lags; | |
%do; | |
lag_&var.&j = lag&j(&var); | |
%end; | |
%end; | |
%end; | |
%mend lag; | |
data test; | |
set sashelp.class; | |
%lag(age height name sex, 4); /* variables to create lag_xxx to var xxx */ | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment