SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Babloo
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
3 REPLIES 3
novinosrin
Tourmaline | Level 20
Qtr_Diff=intck('qtr', start_qtr, end_qtr);
mkeintz
PROC Star

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

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

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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