This code is a SAS Data Step program that processes...
This code is a SAS Data Step program that processes data from an input dataset (df_new
) and creates an output dataset (transitions
). It essentially checks for specific transitions in the data concerning a variable, Default_Ind_OblgrAbsorb
, for each combination of Rating_Bucket
and Oblgr_Nbr
. Below is an explanation of its components and its functionality:
-
Input and Grouping:
- The
set df_new;
statement reads the input dataset (df_new
). - The
by Rating_Bucket Oblgr_Nbr;
statement processes the data grouped byRating_Bucket
andOblgr_Nbr
. Theby
statement allows you to operate within each group.
- The
-
Retain Variables:
- The
retain
statement ensures that the values ofprev_val
andprev_date
persist across rows within the same group (Oblgr_Nbr
).
- The
-
Reset Variables for a New Group:
- The
if first.Oblgr_Nbr then do;
block initializesprev_val
andprev_date
to missing when a newOblgr_Nbr
group starts. Thefirst.Oblgr_Nbr
variable is automatically set to 1 for the first row of eachOblgr_Nbr
group.
- The
-
Check for a Specific Transition:
- The condition
if prev_val=0 and Default_Ind_OblgrAbsorb=1 then do;
checks if there was a transition from 0 (prev_val
) to 1 (Default_Ind_OblgrAbsorb
). - The next condition inside this block,
if bi_dt = intnx('qtr',prev_date,1,'s') then output;
, verifies if the transition occurred in the next calendar quarter. This is done usingintnx('qtr',prev_date,1,'s')
, which calculates the start date of the next quarter afterprev_date
. If the transition occurs in this next quarter, the row is written to the output dataset using theoutput
statement.
- The condition
-
Update Retained Values:
- The
prev_val
variable is updated to the current value ofDefault_Ind_OblgrAbsorb
. - The
prev_date
variable is updated to the current value ofbi_dt
.
- The
-
Output Columns:
- The
keep Rating_Bucket Oblgr_Nbr bi_dt;
statement ensures only these three columns (Rating_Bucket
,Oblgr_Nbr
, andbi_dt
) are kept in the output dataset.
- The
Summary:
This code checks for cases where Default_Ind_OblgrAbsorb
transitions from 0 to 1 for the same Oblgr_Nbr
, and where this transition occurs exactly in the next quarter relative to the prior observation's date (bi_dt
). The resulting rows are written to the transitions
dataset with only the Rating_Bucket
, Oblgr_Nbr
, and bi_dt
columns.