I would like to understand how to identify the quarter difference between two dates. I knew that it can achieved by intck function but I'm not certain how to accomplish with that function.
Suppose I've the data as given below. Both the variables are numeric.
Start_qtr | End_qtr |
2017-03 | 2017-09 |
2017-06 | 2018-03 |
Now I want to calculate quarter difference by creating the new variable 'Qtr_diff' and it should have the value of difference between Start_qtr and End_qtr.
Start_qtr | End_qtr | Qtr_Diff |
2017-03 | 2017-09 | 2 |
2017-06 | 2018-03 | 3 |
Qtr_Diff=intck('qtr', start_qtr, end_qtr);
Are you talking about calendar quarters, or fiscal quarters? I ask this because, for a company whose fiscal year ends in (say) october, then the quarter difference between Jan (end of fiscal Q1) and Feb (start of fiscal Q2) is 1.
In this case you would need to adjust the argument ('QTR') in intck('qtr',begdate,enddate). If, say you have a variable fyend_month (fiscal year end month, with values 1 to 12), you could:
interval==catx('.','qtr',mod(fyend_month,3)+1);
nqtr=intck(interval,begdate,enddate);
This generates intervals of 'QTR.1' (equivalent to 'QTR'), 'QTR.2', or 'QTR.3'. These specify quarters as beginning in the first month of the calendar quarter ('qtr.1'), beginning in the second month of the calendar quarter ('qtr.2'), or the third ('qtr.3').
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.