Hi Sir
I understand that there are different ways of getting the required results without populating BQR1 to BQR12. The SAS code you presented is one such example.
I just wanted wanted to understand the SAS process to get all the 3 queries addressed in the same SAS program.
The SAS code that Patrick provided helped me also understand the SAS process through which I can populate some variables at time t by looking at the performance in next n months.
Regards
Here is how you could add your flags into the one step:
proc sql;
create table want as
select H1.acct_id
,min(H1.snapshot_date) as Start_Date format = date9.
,H2.Default_Date format = date9.
,case
when intck('MONTH', calculated Start_Date, H2.Default_Date, 'C') <= 12 then 1
else 0
end as Default_Flag
,H3.Writeoff_Date format = date9.
,case
when calculated Default_Flag = 1 and intck('MONTH', calculated Start_Date, Writeoff_Date, 'C') <= 60 then 1
else 0
end as Writeoff_Flag
from credit_data as H1
left join
(select acct_id
,min(snapshot_date) as Default_Date
from credit_data
where BQR = '9'
group by acct_id
) as H2
on H1.acct_id = H2.acct_id
left join
(select acct_id
,min(snapshot_date) as Writeoff_Date
from credit_data
where BQR = 'W'
group by acct_id
) as H3
on H1.acct_id = H3.acct_id
group by H1.acct_id
;
quit;
@Skb19121985 wrote:
3) I am expected to create variables BQR_1 to BQR_12 and populate values from the variable BQR for the next 12 months
If you create these variables ahead of time you don't have to loop for 1 as you seem to think. You can use them in the current row.
1) For each observation date corresponding to a given acct_id, I am expected to check in the next 12 months including the given observation month for BQR , if it gets a value 9 then declare that acct_id at the given date to have a default_flag = 1 else 0
WHICHC searches a set of variables, BRQ1-BRQ12 to see if there's a value of 9.
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!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.