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

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

SASKiwi
PROC Star

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;
Reeza
Super User

@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. 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 17 replies
  • 3777 views
  • 3 likes
  • 5 in conversation