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

 

Hi All,

 

I have the following dataset

 

data have;

input account_id reporting_date payment_day;
informat reporting_date  date9.;
format reporting_date  date9.;
cards;
1000 31JAN2017 31
1000 28FEB2017 31
1000 31MAR2017 31
1000 30APR2017 31
1000 31MAY2017 31
2000 31JAN2017 30
2000 28FEB2017 30
2000 31MAR2017 30
2000 30APR2017 30
;
run

I need to calculate the day a payment will be due each month based on reporting date and payment day. I can simply merge the payment day to reporting date but for instance there are not 31 days in Feb and for any month without 31 days I will be returned with missing values.

 

 

How can I get the dataset below using the data above

 

 

account_idreporting_datepayment_daypayment_due_date
100031-Jan-173131-Jan-17
100028-Feb-173128-Feb-17
100031-Mar-173131-Mar-17
100030-Apr-173130-Apr-17
100031-May-173131-May-17
200031-Jan-173030-Jan-17
200028-Feb-173028-Feb-17
200031-Mar-173030-Mar-17
200030-Apr-173030-Apr-17

 

 

Adnan

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

You want payment day on day PD of the month.  If the month is too short  to have day PD, then use end-of-month:

 

data have;
  input account_id reporting_date payment_day;
  informat reporting_date  date9.;
  payment_date=  min(intnx('month',reporting_date,-1,'end')+payment_day
                    ,intnx('month',reporting_date,0,'end'));

  format reporting_date payment_date date9.;
cards;
1000 31JAN2017 31
1000 28FEB2017 31
1000 31MAR2017 31
1000 30APR2017 31
1000 31MAY2017 31
2000 31JAN2017 30
2000 28FEB2017 30
2000 31MAR2017 30
2000 30APR2017 30
;
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

--------------------------

View solution in original post

1 REPLY 1
mkeintz
PROC Star

You want payment day on day PD of the month.  If the month is too short  to have day PD, then use end-of-month:

 

data have;
  input account_id reporting_date payment_day;
  informat reporting_date  date9.;
  payment_date=  min(intnx('month',reporting_date,-1,'end')+payment_day
                    ,intnx('month',reporting_date,0,'end'));

  format reporting_date payment_date date9.;
cards;
1000 31JAN2017 31
1000 28FEB2017 31
1000 31MAR2017 31
1000 30APR2017 31
1000 31MAY2017 31
2000 31JAN2017 30
2000 28FEB2017 30
2000 31MAR2017 30
2000 30APR2017 30
;
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

--------------------------

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1 reply
  • 1437 views
  • 0 likes
  • 2 in conversation