- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Qtr_Diff=intck('qtr', start_qtr, end_qtr);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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').
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content