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
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.
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.
thank you!
it worked well
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: