05-07-2013 12:40 PM
Hello! I have a question which I'm sure is very easy, but I'm stumped.
How do I generate lags of multiple variables at once? I have 105 variables -- each variable I need to lag once and twice.
I've created an array, and tried a number of DO statements, but nothing seems to work. Anyone have any ideas?
05-07-2013 02:07 PM
Something like this could work. But you have to be careful with you first.keyword to reset all the lag values to . so it doesn't carry over the value from prior record...
but this piece of code should get you started:
select cat("prev_",name,"= lag(",name,");") into: my_list separated by " "
where libname = "SASHELP" & memname = "CLASS" ;
All you need to change is the name of your library (WORK?) and the name of the dataset. Make sure you use CAPS.
05-07-2013 06:28 PM
array vars <your list of vars here>;
array L1vars <your list of vars prefixed with L1 here>;
array L2vars <your list of vars prefixed with L2 here>;
Do i = 1 to dim(vars);
L1Vars = lag(vars);
L2Vars = lag2(vars);
should work unless you make the do loop conditional.
The LAG2 variables will be blank for the first two records and the Lag variables blank on the first record.