DATA Step, Macro, Functions and more

How to remove records after flag has reached certain value

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

How to remove records after flag has reached certain value

Hi all,

 

I have the following data in my input dataset.

 

loan_id period DEFAULT_FLAG..

1234     144     0

1234     145     0

1234     146     0

1234     147     0

1234     148     1

1234     149     0

1234     150     1

1234     151     0

 

In this example, loan_id 1234 and one row for each period. I need only the records until the first time default_flag has value 1.

Following is the expected output:

 

loan_id period DEFAULT_FLAG..

1234     144     0

1234     145     0

1234     146     0

1234     147     0

1234     148     1

 

The data is sorted on loan_id and period.

 

Can anyone please help me achieve this.

 

Thanks


Accepted Solutions
Solution
‎11-21-2017 10:38 AM
Respected Advisor
Posts: 2,989

Re: How to remove records after flag has reached certain value

Posted in reply to UshaLatha

UNTESTED CODE

 

data want;
    set have;
    by loan_id period;
    if first.loan_id then sum_flag=0;
    sum_flag+default_flag;
    if sum_flag=0 or (sum_flag=1 and default_flag=1) then output;
run;
--
Paige Miller

View solution in original post


All Replies
Solution
‎11-21-2017 10:38 AM
Respected Advisor
Posts: 2,989

Re: How to remove records after flag has reached certain value

Posted in reply to UshaLatha

UNTESTED CODE

 

data want;
    set have;
    by loan_id period;
    if first.loan_id then sum_flag=0;
    sum_flag+default_flag;
    if sum_flag=0 or (sum_flag=1 and default_flag=1) then output;
run;
--
Paige Miller
Contributor
Posts: 31

Re: How to remove records after flag has reached certain value

Posted in reply to PaigeMiller

Thanks very much !!!

the code is working perfectly

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 134 views
  • 0 likes
  • 2 in conversation