DATA Step, Macro, Functions and more

Date logic

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Date logic

Hi,

I have a statement end date that I need to figure the statement start date, which is exactly the same day but in the month previous.

for example

id bill_end_date bill_st_date

1 12Jan2011 12Dec2010

2 23Feb2011 23Jan2011

etc.

thanks for your help.


Accepted Solutions
Solution
‎02-01-2012 01:25 PM
Respected Advisor
Posts: 3,124

Date logic

Something like this may get your started:

data have;

infile cards;

format bill_end_date date9.

       bill_st_date date9.;

input id bill_end_date : date9.;

bill_st_date=intnx('mon', bill_end_date,-1,'sameday');

cards;

1 12Jan2011

2 23Feb2011

;

proc print;run;

Kindly Regards,

Haikuo

View solution in original post


All Replies
Super User
Posts: 17,868

Date logic

intnx function with the same option.

Check the docs.

Solution
‎02-01-2012 01:25 PM
Respected Advisor
Posts: 3,124

Date logic

Something like this may get your started:

data have;

infile cards;

format bill_end_date date9.

       bill_st_date date9.;

input id bill_end_date : date9.;

bill_st_date=intnx('mon', bill_end_date,-1,'sameday');

cards;

1 12Jan2011

2 23Feb2011

;

proc print;run;

Kindly Regards,

Haikuo

Contributor
Posts: 66

Date logic

thank you for your help.

what happens to months with 31 days? I assume it goes to month end?

Respected Advisor
Posts: 3,124

Date logic

Bingo! It will go to the last day of the month. Try it for yourself, change 12Jan2011 to 31Mar2011, and see what happens.

Regards,

Haikuo

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 182 views
  • 0 likes
  • 3 in conversation