DATA Step, Macro, Functions and more

Is it possible to show obs when happens something and immediately next obs?

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

Is it possible to show obs when happens something and immediately next obs?

I have a dataset with multiple obs.

 

 

I only want to show obs when occur some condition and immediately next obs.

 

I dont want to put two conditions because other obs can satisfy.

 

Is it possible?

 

thanks


Accepted Solutions
Solution
‎11-11-2017 02:45 PM
Esteemed Advisor
Posts: 5,398

Re: Is it possible to show obs when happens something and immediately next obs?

Sure, using a RETAINed variable. Here is an example:

 

data want;
retain flag;
set sashelp.class;
condition = age = 14;
if flag then output;
else if condition then output;
flag = condition;
drop flag condition;
run;
PG

View solution in original post


All Replies
Solution
‎11-11-2017 02:45 PM
Esteemed Advisor
Posts: 5,398

Re: Is it possible to show obs when happens something and immediately next obs?

Sure, using a RETAINed variable. Here is an example:

 

data want;
retain flag;
set sashelp.class;
condition = age = 14;
if flag then output;
else if condition then output;
flag = condition;
drop flag condition;
run;
PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 136 views
  • 0 likes
  • 2 in conversation