I have this code (don't consider a data snippet necessary in this case, let me know).
data temp;
set test;
by id;
lag_1=lag(var1);
lag_2=lag(var2);
lag_3=lag(var3);
lag_4=lag(var4);
lag_5=lag(var5);
if first.id then lag_:=.;
run;
I tried this and on the last line it gives me an error: "statement is not valid or it is used out of proper order".
I also tried to do
if first.id then lag_1-lag_5=.;
but it gives me the same error.
I'm sure this is very stupid, but how can I do it so that I don't have to write all 5 (in reality I have around 60 lagged variables I need to do, hence why I need the short way)?
You can use CALL MISSING() to set multiple variables to missing on one function call.
if first.id then call missing(of lag_:);
You can use CALL MISSING() to set multiple variables to missing on one function call.
if first.id then call missing(of lag_:);
CALL MISSING will set a list of variables to missing values.
Call missing is also one of the few functions that will take both numeric and character variables in a single function call.
if first.id then call missing (lag_1 - lag_5);
In general you only get one variable as the target of an = sign.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.