BookmarkSubscribeRSS Feed
CSONNYC
Calcite | Level 5

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!

5 REPLIES 5
Reeza
Super User

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;

CSONNYC
Calcite | Level 5

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?

PGStats
Opal | Level 21

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
Reeza
Super User

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;

CSONNYC
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 862 views
  • 4 likes
  • 3 in conversation