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

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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
UshaLatha
Obsidian | Level 7

Thanks very much !!!

the code is working perfectly

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 686 views
  • 0 likes
  • 2 in conversation