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-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!

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.

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
  • 17 replies
  • 9900 views
  • 0 likes
  • 5 in conversation