but 240 mean the no of month from 1219 to when? I still dont get the logic after I tried a few more
1219 240 months
1021 262 months
1217 216 months
1221 264 months
Consider the start of 2000 as the "zero" point, so January of 2000 is month #1. Then this makes sense:
data result;
input YEARS_OF_IMP $5.;
month =
(
input(YEARS_OF_IMP,4.)
-
int(
input(YEARS_OF_IMP,4.) / 100
) * 100 /* subtract the left two digits (100 and 1000 order of magnitude) from the number */
) * 12 /* and multiply the remaining by 12, indicating that this is a year number */
+
int(
input(YEARS_OF_IMP,4.) / 100
) /* and add the first two digits, so these are the months */
;
datalines;
0100
0200
0101
0422
;
You will get results of 1, 2,13 and 268. April 2022 is the 268th month after December 1999.
TBH, someone who writes such a formula into code, without leaving proper documentation (or at least a comment in the code) that details the function and intent, should be hung, drawn and quartered. Or at least have their behind paddled in front of the whole department. Let this be a lesson to yourself: whenever you have to write code that is not immediately understandable at first glance, write a comment to explain what happens. Also do that whenever you are forced to write code that causes a non-standard NOTE (like "More than one datasets has repeating BY values" in a MERGE)
@HeatherNewton wrote:
why are you sure it is mmyy format ?
See my dissection of the formula.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.