BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Judy_w
Calcite | Level 5

Hello everyone,

This problem bothered me a lot, could you have a look and advice on how I can solve this problem? thanks!

 

I have a dataset which has the structure as follows:

ID is the customer ID that has default;

open_month means = -60 means the bank account is opened before 60 months, the value of this column is from -60 to 0;

MOB is the month on book, the value is from 0-60;

 

I'm trying to do a vintage analysis, so I need to calculate the accumulated number of default customers by open month and MOB, the structure of the output dataset should be open_month, MOB, count of accumulated distinct customer ID.

 

For example, for the combination of open_month = -60 and MOB = 10 should count all distinct ID where open_month = -60 and MOB <=10, hope I describe it clearly.

 

 

IDopen_monthMOB
5069216-605
5069216-606
5023640-607
5023644-607
5069216-607
5069216-609
5116761-609
5069216-6010
5059854-6011
5069216-6011
5116761-6011
5002283-6012
5059854-6012
5069216-6012
5116761-6012
5059854-6013
5085886-6013
5116761-6013
5085886-6014
5116761-6014
5085886-6015
5085886-6016
5085886-6017
5085886-6018
5085886-6019
5085886-6020
5065314-6021
5085886-6021
5065314-6022
5085886-6022
5065314-6023
5085886-6023
5065314-6024
5085886-6024
5060452-6025
5065314-6025
5085886-6025

 

Your kindly help is highly appreciated!

 

Best Regards

 

Judy

1 ACCEPTED SOLUTION

Accepted Solutions
qatman28
Obsidian | Level 7

A quick and dirty version would be something like:

 

data expand;
  set have;
  do mobx = 0 to 60;
    if mob <= mobx then output;
  end;
run;

proc sort data=expand out=unique_combos (keep=id open_month mobx) nodupkey;
  by open_month mobx id;

data want;
  set unique_combos;
  by open_month mobx;
  retain count;
  if first.mobx then count = 0;
  count + 1;
  if last.mobx then output;
run;

Basically this outputs all qualifying records by id/open_month/mobx, then restricts to at most one per ID, then counts the number of qualifying IDs. There are of course many ways to do it but this is a fairly simple and understandable method.

View solution in original post

2 REPLIES 2
qatman28
Obsidian | Level 7

A quick and dirty version would be something like:

 

data expand;
  set have;
  do mobx = 0 to 60;
    if mob <= mobx then output;
  end;
run;

proc sort data=expand out=unique_combos (keep=id open_month mobx) nodupkey;
  by open_month mobx id;

data want;
  set unique_combos;
  by open_month mobx;
  retain count;
  if first.mobx then count = 0;
  count + 1;
  if last.mobx then output;
run;

Basically this outputs all qualifying records by id/open_month/mobx, then restricts to at most one per ID, then counts the number of qualifying IDs. There are of course many ways to do it but this is a fairly simple and understandable method.

Judy_w
Calcite | Level 5

Thank you so much! You are brilliant!

I just add one step to remove records which mobx > -(open_month).

Thank you again! You made my day!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1172 views
  • 1 like
  • 2 in conversation