DATA Step, Macro, Functions and more

intnx to decrement quarter year

Reply
Frequent Contributor
Posts: 83

intnx to decrement quarter year

Hi,

Does anyone know any function like intnx to increment or decrement quarteryear

if sysdate is 19oct2010 -- quarter year would be Q4 2010

I need

Q4 2010
Q3 2010
Q2 2010
Q1 2010
Q4 2009

Thankx
Respected Advisor
Posts: 3,799

Re: intnx to decrement quarter year

I think you just need to FORMAT the date.

[pre]
proc format;
picture QYYYY(default=9) other='Q%q %Y' (datatype=date);
run;

data _null_;
d = '19oct2010'd;
put d=yyq. d=Qyyyy.;
run;
[/pre]
Frequent Contributor
Posts: 83

Re: intnx to decrement quarter year

Posted in reply to data_null__
Thankyou.

Actually i need a function which is capable of reducing the qtr and year back say by a factor of n.
Super Contributor
Super Contributor
Posts: 3,174

Re: intnx to decrement quarter year

The OP original post asked for a way to display a date as a quarter-year.

Otherwise, consider the INTNX function and QTR (argument #1). Check the SAS Language Dictionary DOC discussion on INTNX for details.

Scott Barry
SBBWorks, Inc.
Respected Advisor
Posts: 3,799

Re: intnx to decrement quarter year

INTNX?

[pre]
870 data _null_;
871 d = '19oct2010'd;
872 do o = -4 to 4;
873 q = intnx('QTR',d,o);
874 put q=date9. q=yyq.;
875 end;
876 run;

q=01OCT2009 q=2009Q4
q=01JAN2010 q=2010Q1
q=01APR2010 q=2010Q2
q=01JUL2010 q=2010Q3
q=01OCT2010 q=2010Q4
q=01JAN2011 q=2011Q1
q=01APR2011 q=2011Q2
q=01JUL2011 q=2011Q3
q=01OCT2011 q=2011Q4
[/pre]
Ask a Question
Discussion stats
  • 4 replies
  • 320 views
  • 0 likes
  • 3 in conversation