DATA Step, Macro, Functions and more

INTNX producing unexpected results

Reply
New Contributor
Posts: 3

INTNX producing unexpected results

Hi,

I have a datastep that looks like this:

data new_orig1;

set new_orig;

format orig_date mmddyy10. MaturityDate mmddyy10. groupdsfinalscaled 12.;

orig_date = intnx('quarter','30sep12'd,quarter);

curr_dt = put(put(orig_date,yyq6.),$6.);

run;

I would expect that all the resulting values for "orig_date" would be Oct 1, 2012, since the input date, '30sep12'd, is a constant for all the observations. But for some reason, this only occurs for a subset of my resulting dataset. The rest of the observations have "orig_date" values such as 1/1/2013, 4/1/2013, 7/1/2013, 10/1/2013. In other words, always the beginnings of quarters, but not 10/1/2012 as I had expected.

Can anyone explain why?

Much appreciated!

Super User
Posts: 19,815

Re: INTNX producing unexpected results

Is quarter ever equal to 1, because that would give you the date you expect. If not, then no....

data new_orig1;

format orig_date mmddyy10. ;

orig_date = intnx('quarter','30sep12'd,1);

curr_dt = put(put(orig_date,yyq6.),$6.);

run;

New Contributor
Posts: 3

Re: INTNX producing unexpected results

Thanks Reeza! You're right, all the sample syntax for the INTNX statement I am finding has a constant as the interval. I'm not sure how exactly having the interval set to "quarter" instead of "1" results in some of the resulting observations having an "orig_date" of 10/1/2012, some having 1/1/2013, some having 4/1/2013, etc. Do you know how this works?

Respected Advisor
Posts: 4,925

Re: INTNX producing unexpected results

The third parameter in INTNX is the number of intervals by which to shift the date. If you want the quarter where your date belongs, use 0 as the third parameter (+1 gives you the next, -1, the previous, quarter)

PG

PG
Super User
Posts: 19,815

Re: INTNX producing unexpected results

The parameters for intnx are

Interval - "Quarter"

Start date -  '30Sep2012'd

INCREMENT - quarter (variable I'm assuming????)

Alignment (optional) - default = start of period.

You've set your interval to quarters, so every 3 months and your start date to the end of September. The next quarter or interval would be October 1, 2012.


Your increment is set to a variable named quarter. Run a proc freq on your quarter variable to see what that value contains, my guess is 1/2/3/4/5...etc, so your original start date is being incremented by the value in each of the observations.

proc freq data=  new_orig;

table quarter;

run;

New Contributor
Posts: 3

Re: INTNX producing unexpected results

You're right! I just ran a proc freq and now understand it complete. Thanks so much for your help!

Ask a Question
Discussion stats
  • 5 replies
  • 240 views
  • 4 likes
  • 3 in conversation