0

sorry it is probably a very simple question, but I can't seem to find an answer to it.

Say, we want to create a table that contains 4 quarters back from the previous month:

%macro asd;

%let today = %sysfunc(today());

%let quarter_count_back = 4;

%let first_quarter = %sysfunc(intnx(month,&today.,-1));

proc sql;
create table quarters
(
Quarters num informat = date9. format = date9.
);
insert into quarters

%do i = 0 %to -&quarter_count_back.+1 %by -1;

values(%sysfunc(intnx(quarter,&first_quarter.,&i.)))

%end;
;
quit;


run;
%mend asd;
%asd;
run;

This code works just fine and creates a table, which starts from APR2016 and goes back in time by quarter. However, if I change the number in the 'first_quarter' line for -2, -3 etc... the code always starts from JAN2016 which just doesn't make any sense to me! For example:

%let first_quarter = %sysfunc(intnx(month,&today.,-2));

It seems logical that if I put this line in the code the table should start from MAR2016 and go back by quarter, but it does not, it starts from JAN2016.

Any ideas on what I am doing wrong here?

Thanks!

1
  • Look at what the fourth parameter is for INTNX and the default behaviour. You want 's' or same.
    – Reeza
    May 2, 2016 at 19:37

1 Answer 1

0

The default alignment for the INTNX function is the beginning of the interval. If you want it to go back 3 months, that's different than quarters. You can adjust these by looking at the fourth parameter of the INTNX function which controls the alignment. Options are:

  • Same
  • Beginning
  • End

If you want three months, try the MONTH.3 interval instead of quarter.

http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p10v3sa3i4kfxfn1sovhi5xzxh8n.htm

2
  • Thanks! Only the 'same' alignment worked, however. I am not sure, but why 'end' alignment didn't work? It seems logical to loop back by it... BTW isn't a quarter the same as 3 months?
    – Kvadich
    May 3, 2016 at 15:32
  • From what I understand, Quarters are the specific intervals - Jan- Mar, whereas 3 months can be any 3 months Feb to Apr for example.
    – Reeza
    May 3, 2016 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.