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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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