BookmarkSubscribeRSS Feed
Adnan2
Fluorite | Level 6

Hi All,

 

I have the following data

 

accountidMonthCreditDebitMonth_End_BalanceMin_Pay
123202310.565.54565.5412.56
123202310565.54.565.5412.56
123202311.317.63883.1718.98
123202311317.63.883.1718.98
123202312.1184.242067.4145.98
1232023121184.24.2067.4145.98
123202401.208.12275.5147.32
123202401208.1.2275.5147.32
123202402.-1311.05964.4619.87
123202402-1311.05.964.4619.87
456202310.31.8631.863.09
456202311.845.94877.818.76
456202311845.94.877.818.76
456202312.-415.08462.729.34
456202312-415.08.462.729.34
456202401.-71.94390.788.76
456202401-71.94.390.788.76
456202402.657.291048.0720.08
456202402657.29.1048.0720.08

 

 

1.) how can I have a single record per month per account. At the moment the credits and debits are being recorded on separate records

 

2.) from the data above how can I calculate the arrears by month? 

 

Thanks in advance 

6 REPLIES 6
Astounding
PROC Star

Given that  your data set is sorted this would be one way:

proc summary data=have;
  var credit debit min_pay;
  by accountid month;
  out=want (drop=_: ) max=;
run;
mkeintz
PROC Star

Assuming data are sorted by accountid/month and each id/month has either a qualifying credit obs or qualifying debit obs (or both) you can:

 

data want;
  merge have (where=(credit^=.))  have (where=(debit^=.));
  by accountid month;
run;

And what is your project's operational definition of arrears?

 

Edited note:  Go see @Astounding's catch of my oversight.  (Should have had ("drop = credit") as an additional data set name parameter in the 2nd argumnet of the MERGE statement.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

An interesting approach, which would work with a slight tweak:

 

data want;
  merge have (where=(credit^=.))  have (drop=credit where=(debit^=.));
  by accountid month;
run;

 

It also suggests another possibility:

 

data want;
  update have (where=(credit^=.))  have;
  by accountid month;
run;

 

 

mkeintz
PROC Star

@Astounding wrote:

An interesting approach, which would work with a slight tweak:

 

data want;
  merge have (where=(credit^=.))  have (drop=credit where=(debit^=.));
  by accountid month;
run;

 

It also suggests another possibility:

 

data want;
  update have (where=(credit^=.))  have;
  by accountid month;
run;

 

 


Oops.  Thanks

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
mkeintz
PROC Star

Or, as I now recall, a solution frequently posted by others:

 

data want;
  update have (obs=0) have;
  by accountid month;
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SASKiwi
PROC Star

What is your definition of arrears? An actual example would be good. There are many different ways to calculate arrears so you need to tell us what your method is.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 6 replies
  • 524 views
  • 2 likes
  • 4 in conversation