BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amanjot_42
Fluorite | Level 6

Hi guys,

 

I am trying to find out the difference between two quarter dates. My data looks like:

 

Fiscal_quarter  Event_quarter

2007Q1  2008Q3

2007Q2  2008Q3

2007Q3  2008Q3

2007Q4  2008Q3

2008Q1  2008Q3

2008Q2  2008Q3

2008Q3  2008Q3

2008Q4  2008Q3

2009Q1  2008Q3

2009Q2  2008Q3

2009Q3  2008Q3

2009Q4  2008Q3

 

I want to find out difference between fiscal quarters and event quarter. For instance, when fiscal and event quarter are same, I want 0 as a new variable. Similarly, for one quarter before, it should be -1 and one quarter after the event quarter should be 1, and so on. Please suggest me how can I do this? I tried using this code:

 

qtr_num = intck('qtr', datafqtr, ad)

 

but ended up with errors saying invalid numeric data.

 

Cheers

Amanjot

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Maxim 3: Know Your Data.

You need numeric data as second and third arguments for the intck() function, and they have to be SAS date values (count of days from 1960-01-01).

Maxim 33: Intelligent Data Makes for Intelligent Programs.

Date values should always be stored as such; keeping them in character variables makes coding harder and must be avoided.

So if your input data looks as you posted, convert it when importing into SAS:

data have;
input Fiscal_quarter :yyq6. Event_quarter :yyq6.;
format Fiscal_quarter :yyq6. Event_quarter yyqn6.;
datalines;
2007Q1  2008Q3
2007Q2  2008Q3
2007Q3  2008Q3
2007Q4  2008Q3
2008Q1  2008Q3
2008Q2  2008Q3
2008Q3  2008Q3
2008Q4  2008Q3
2009Q1  2008Q3
2009Q2  2008Q3
2009Q3  2008Q3
2009Q4  2008Q3
;

data want;
set have;
qtr_num = intck('qtr', Fiscal_quarter, Event_quarter);
run;

and the function will work.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

Maxim 3: Know Your Data.

You need numeric data as second and third arguments for the intck() function, and they have to be SAS date values (count of days from 1960-01-01).

Maxim 33: Intelligent Data Makes for Intelligent Programs.

Date values should always be stored as such; keeping them in character variables makes coding harder and must be avoided.

So if your input data looks as you posted, convert it when importing into SAS:

data have;
input Fiscal_quarter :yyq6. Event_quarter :yyq6.;
format Fiscal_quarter :yyq6. Event_quarter yyqn6.;
datalines;
2007Q1  2008Q3
2007Q2  2008Q3
2007Q3  2008Q3
2007Q4  2008Q3
2008Q1  2008Q3
2008Q2  2008Q3
2008Q3  2008Q3
2008Q4  2008Q3
2009Q1  2008Q3
2009Q2  2008Q3
2009Q3  2008Q3
2009Q4  2008Q3
;

data want;
set have;
qtr_num = intck('qtr', Fiscal_quarter, Event_quarter);
run;

and the function will work.

amanjot_42
Fluorite | Level 6

thank you!

it worked well

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1588 views
  • 1 like
  • 2 in conversation