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. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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