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

hey 🙂

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

4 REPLIES 4
Shmuel
Garnet | Level 18

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.

Astounding
PROC Star

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?

AravindanKarunakaran
Calcite | Level 5

dur_month = dur_day/30.4375;

 

365.25 days per year.

 

365 days in normal year

366 days in Leap year

0.25 days * 4 year becomes extra day in Leap year

 

so, 365.25/12 = 30.4375 days per month


@kathisas wrote:

hey 🙂

 

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


 

Cerium23
Calcite | Level 5

How do you calculate days to months in SAS? I actually have days like 1575757. I need to convert this. Help. 

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
  • 4 replies
  • 17738 views
  • 3 likes
  • 5 in conversation