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
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;
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;
Thanks very much !!!
the code is working perfectly
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.