BookmarkSubscribeRSS Feed
Rhodochrosite | Level 12

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
Tourmaline | Level 20
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: 


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

Rhodochrosite | Level 12
Source data is connected with only calendar quarter.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


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.

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
  • 3 in conversation