DATA Step, Macro, Functions and more

calculate days in month

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

calculate days in month

hey Smiley Happy

 

pleas help me.

 

I have to calculate an observation time between two dates and sas calculates the days of the periode. How can I get sas to calculate it in months?

 

thank you for your help


Accepted Solutions
Solution
‎03-13-2017 01:45 PM
Super User
Posts: 5,495

Re: calculate days in month

A simple approach would transform the number of days into number of months:

 

n_months = (date2 - date1) / 30.5;

 

Do you have different rules in mind for computing number of months?

View solution in original post


All Replies
Trusted Advisor
Posts: 1,552

Re: calculate days in month

[ Edited ]

Assuming you have sas numeric dates then you can use:

   period = intck('month',date2,date1);

 

If your data containd datetime variables you should use datepart() function

to convert datetime into sas date.

Solution
‎03-13-2017 01:45 PM
Super User
Posts: 5,495

Re: calculate days in month

A simple approach would transform the number of days into number of months:

 

n_months = (date2 - date1) / 30.5;

 

Do you have different rules in mind for computing number of months?

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 598 views
  • 3 likes
  • 3 in conversation