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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 384 views
  • 1 like
  • 2 in conversation