BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sandeep77
Lapis Lazuli | Level 10

Hi all,

I have a data set with debt_code, icustomerid, datekey and flag. I want to count the debt_code with unique datekey. This is to check how many times that debt_code has entered in same icustomerid. I am not sure how to write a code for it. I am looking to add a column which can show me how many times a particular debt_code has entered same icustomerid on different dates. For e,g, 266208776 has entered 21436 icustomerid 4 times on different dates (datekey). Can anyone assist what would be the best way to find it out?

Sample data. 
debt_code	icustomerid	datekey	flag
286338454	16418	   20220406	  0
295191266	16418	   20220406	  0
299889733	16418	   20220406	  0
266208776	21436	   20190207	  1
266208776	21436	   20190911	  1
266208776	21436	   20200109	  1
266208776	21436	   20201207	  1
291458610	21436	   20190911	  1
291458610	21436	   20190917	  1
291458610	21436	   20200109	  1
291458610	21436	   20201207	  1

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

SQL approach:

proc sql;
create table want as
  select
    debt_code,
    icustomerid,
    count(*) as count
  from have
  group by debt_code, icustomerid
;
quit;

PROC FREQ method:

proc summary data=have nway;
class debt_code icustomerid;
var datekey;
output out=want n(datekey)=count;
run;

Untested; for tested code, post data in usable form in a working data step with datalines.

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

SQL approach:

proc sql;
create table want as
  select
    debt_code,
    icustomerid,
    count(*) as count
  from have
  group by debt_code, icustomerid
;
quit;

PROC FREQ method:

proc summary data=have nway;
class debt_code icustomerid;
var datekey;
output out=want n(datekey)=count;
run;

Untested; for tested code, post data in usable form in a working data step with datalines.