Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created March 7, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/cb52f1a54868e959a838f2b6f3dfad20 to your computer and use it in GitHub Desktop.
Save statgeek/cb52f1a54868e959a838f2b6f3dfad20 to your computer and use it in GitHub Desktop.
SAS Macro to create lagged time series data for variables
%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