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

hi there,

 

I am trying to calculate age as the number of total months as of a specific date. But I am getting the number of years. Please help me to fix this issue? 

DATA  AGE_MONTHS;
SET TEST;
TODAY = MDY(03,31,2021);
DAYS = TODAY - Launch_Date;
AGE=FLOOR((INTCK('month',Launch_Date,TODAY) - (DAY(TODAY) < DAY(Launch_Date))) / 12);
RUN;

regards,

sara

 

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

You are already using the INTCK Function and specifying "MONTH" as the interval so why divide by 12?

View solution in original post

3 REPLIES 3
AMSAS
SAS Super FREQ

You are already using the INTCK Function and specifying "MONTH" as the interval so why divide by 12?

saraphdnz
Quartz | Level 8

THANKS HEAPS.

ballardw
Super User

You may want to consider use of the INTCK method option='C' such as

INTCK('month',Launch_Date,TODAY,'C')

The default of 'D' or discrete may not yield quite what you want.

Consider this example:

data example;
   date1 = '18Mar2021'd;
   date2 = '02Jul2021'd;
   default = intck('month',date1,date2);
   cont    = intck('month',date1,date2,'C');
run;

Decide what you would expect to be the number of months between those two dates (think perhaps of date1 as a date of birth and the other the date of some service). Then run the code and pick the appropriate version.

I used two close together dates intentionally so you can decide before running the code.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 674 views
  • 5 likes
  • 3 in conversation