proc fcmp outlib=SASHELP.SLKWXL.FINANCE LIBRARY=(SASHELP.SLKWXL);
function amordegrc_slk(cost,datep,fperiod,salvage,period,rate,basis)
label="Excel AMORDEGRC";
/*-----------------------------------------------------------------
* ENTRY: amordegrc_slk
*
* PURPOSE: Microsoft Excel's AMORDEGRC function. Returns the
* depreciation for each accounting period. Similar to
* amorlinc function, except that a depreciation
* coefficient is applied.
*
* USAGE: amordegrc = amordegrc_slk(cost,datep,fperiod,salvage,
* period,rate,basis);
* cost - cost of the asset.
* datep - date of the purchase of the asset.
* fperiod - date of the end of the first period.
* salvage - salvage value at the end of the life
* of the asset.
* period - the period.
* rate - the rate of depreciation.e
* basis - type of day count basis.
* basis = 0: US (NASD) 30/360.
* basis = 1: Actual/actual.
* basis = 2: NOT ALLOWED.* basis = 3: Actual/365.
* basis = 4: European 30/360.
*
* NOTES: The depreciation coefficient is different depending one
* the number of years in the life of the asset being
* depreciated. The life of asset is the inverse
* of rate:
*
* rate life of asset depreciation coeff (DC)
* 0.25-0.333 3-4 years 1.5
* 0.1666-0.2 5-6 years 2.0
* < 0.1666 >6 years 2.5
*
* The function will return depreciation until the last
* period of the life of the asset, or until the
* accumulated value of depreciation is greater than the
* cost of the asset minus the salvage value.
*
* For period 0:
* cost*rate*DC*yearfrac(datep, fperiod, basis);
* where yearfrac() calculates the fraction
* of the year represented by the whole days between
* the start_date and end_date.
*
* For periods 1 through lifeofasset - 2:
* (cost - depreciation from previous periods)*rate*DC;
*
* For the period of lifeofasset - 1 through
* the last period of asset's life:
* (cost - depreciation from previous periods)/2;
*
* When the accumulated value of depreciation exceeds the cost
* of the asset minus the salvage value, then the function
* returns zero.
*
*-----------------------------------------------------------------*/
life = 1/rate;
if life > 0 & life < 1 then return(.);
if life > 1 & life < 2 then return(.);
if life > 2 & life < 3 then return(.);
if life > 4 & life < 5 then return(.);
if life > 3 & life < 4 then coeff = 1.5;
if life > 5 & life < 6 then coeff = 2;
if life > 6 then coeff = 2.5;
select(basis);
when(0)
do;
B = 360;
DPF = datdif(datep, fperiod,'30/360');
end;
when(1)
do;
newyeard = intnx('year', datep - 1, 0);
endyeard = intnx('year', datep - 1, 1) - 1;
B = endyeard - newyeard + 1;
DPF = datdif(datep, fperiod, 'act/act');
end;
when(3)
do;
B = 365;
DPF = datdif(datep, fperiod, 'act/365');
end;
when(4)
do;
B = 360;
DPF = datdif4_slk(datep, fperiod);
end;
otherwise
return(.);
end;
depr0 = cost*rate*coeff*DPF/B;
if period = 0 then return(depr0);
if period > life then return(0);
cumdep = depr0;
cms = cost - salvage;
cost = cost - depr0;
n = 1;
if int(period) <= int(life) - 2 then
do;
do while(n <= period & cumdep <= cms );
tempdep = cost*rate*coeff;
cost = cost - tempdep;
cumdep + tempdep;
n + 1;
end;
depr = tempdep;
if cumdep > cms & period >= n then return(0);
else
return(depr);
end;
if int(period) >= int(life) - 1 then
do;
ind = int(life) - 1;
do while(n < ind & cumdep <= cms );
tempdep = cost*rate*coeff;
cost = cost - tempdep;
cumdep + tempdep;
n + 1;
end;
deprl = cost/2;
if int(period) = int(life) - 1 then
do;
if cumdep > cms & period >= n then return(0);
else
return(deprl);
end;
else
if int(period) = int(life) then
do;
if salvage < deprl & cumdep <= cms then return(deprl);
else
return(0);
end;
end;
return(deprl);
endsub;
run;
quit;
|