BookmarkSubscribeRSS Feed
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
SAS made the calculation - not me -- you will need to take it from here. Suggest you follow the SAS function logic in the DOC, then adapt your increment/decrement choice based on SAS-generated results. My expectation is that you will see consistency using the function, but it's your choice to go up or down, as desired, with your SAS application needs.

Scott Barry
SBBWorks, Inc.
LAtwood
Calcite | Level 5
Scott,

Thanks for your help and input on this. I appreciate it.

Lori
Cynthia_sas
SAS Super FREQ
Hi:
Using either a modified version of Scott's method or a modified version of Peter's method, it is possible to either come CLOSE to your 12.6 or exactly hit your 12.677. See the attached modified program and log output. If all you wanted was the 12.6, then either of the modified methods will give you that number. If you want -exactly- 12.677...

cynthia
[pre]
467 data _null_;
468 format s_dt l_dt l_dt_end s_dt_end l_dt_beg date9.;
469 s_dt = mdy(12,25,2008);
470 l_dt = mdy(1,15,2010);
471
472 ** Scott B Original Calc;
473 months = intck('month',s_dt,l_dt);
474 l_dt_end = intnx('month',l_dt,0,'e');
475 dec_month_sb_orig = months + day(l_dt) / day(l_dt_end);
476
477 ** Peter C. Suggestion Modified;
478 dec_months_pc = (l_dt - s_dt) /(365.25/12);
479
480 ** get the END of the start date and the BEGIN of the Last date;
481 s_dt_end = intnx('month',s_dt,0,'e');
482 l_dt_beg = intnx('month',l_dt,0,'b');
483
484 ** because INTCK returns whole intervals, subtract 1 day from the;
485 ** beginning of the last date -- this will give you 12 months instead of 13;
486 newmonth = intck('month',s_dt,l_dt_beg-1);
487
488 ** Now, figure out how many days from the start day to the end of the start month;
489 ** and the number of days in the last date;
490 daysleft = (s_dt_end -s_dt) + day(l_dt);
491
492 ** Do the modified formula using DAYSLEFT and NEWMONTH;
493 dec_month_sb_alt = newmonth + (daysleft / day(l_dt_end));
494
495 putlog s_dt= s_dt_end= l_dt= l_dt_beg= l_dt_end=;
496 putlog '***** ***** ***** *****';
497 putlog "Scott Original Calc:";
498 putlog dec_month_sb_orig=;
499 putlog '***** ***** ***** *****';
500 putlog "Peter Suggestion Modified";
501 putlog dec_months_pc=;
502 putlog '***** ***** ***** *****';
503 putlog "Using DAYSLEFT by modifying Scott's Original Calc";
504 putlog daysleft= newmonth= dec_month_sb_alt=;
505 run;

s_dt=25DEC2008 s_dt_end=31DEC2008 l_dt=15JAN2010 l_dt_beg=01JAN2010 l_dt_end=31JAN2010
***** ***** ***** *****
Scott Original Calc:
dec_month_sb_orig=13.483870968
***** ***** ***** *****
Peter Suggestion Modified
dec_months_pc=12.681724846
***** ***** ***** *****
Using DAYSLEFT by modifying Scott's Original Calc
daysleft=21 newmonth=12 dec_month_sb_alt=12.677419355
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

[/pre]

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 11253 views
  • 0 likes
  • 5 in conversation