BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
catkat96
Obsidian | Level 7

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)?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can use CALL MISSING() to set multiple variables to missing on one function call.

if first.id then call missing(of lag_:);

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You can use CALL MISSING() to set multiple variables to missing on one function call.

if first.id then call missing(of lag_:);
ballardw
Super User

 

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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 718 views
  • 1 like
  • 3 in conversation