The following predefined utility functions are provided with the SEVERITY procedure and are available in the Sashelp.Svrtdist
library:
This function computes the empirical distribution function (EDF) estimate at the specified value of the random variable given the EDF estimate for a sample.
Type: Function
Signature: SVRTUTIL_EDF(y, n, x{*}, F{*}, Ftype)
Argument Description:
Value of the random variable at which the EDF estimate is desired.
Dimension of the x and F input arrays.
Input numeric array of dimension n that contains values of the random variable observed in the sample. These values are sorted in nondecreasing order.
Input numeric array of dimension n in which each F[] contains the EDF estimate for x[]. These values must be sorted in nondecreasing order.
Type of the empirical estimate that is stored in the x and F arrays. See the section Supplying EDF Estimates to Functions and Subroutines for definition of types.
Return value: The EDF estimate at .
The type of the sample EDF estimate determines how the EDF estimate at is computed. See the section Supplying EDF Estimates to Functions and Subroutines for more information.
This function computes the empirical estimate of the limited moment of specified order for the specified upper limit, given the EDF estimate for a sample.
Type: Function
Signature: SVRTUTIL_EMPLIMMOMENT(k, u, n, x{*}, F{*}, Ftype)
Argument Description:
Order of the desired empirical limited moment.
Upper limit on the value of the random variable to be used in the computation of the desired empirical limited moment.
Dimension of the x and F input arrays.
Input numeric array of dimension n that contains values of the random variable observed in the sample. These values are sorted in nondecreasing order.
Input numeric array of dimension n in which each F[] contains the EDF estimate for x[]. These values must be sorted in nondecreasing order.
Type of the empirical estimate that is stored in the x and F arrays. See the section Supplying EDF Estimates to Functions and Subroutines for definition of types.
Return value: The desired empirical limited moment.
The empirical limited moment is computed by using the empirical estimate of the CDF. If denotes the EDF at , then the empirical limited moment of order with upper limit is defined as

The SVRTUTIL_EMPLIMMOMENT function uses the piecewise linear nature of as described in the section Supplying EDF Estimates to Functions and Subroutines to compute the integration.
This function computes an estimate of the value where the right tail of a distribution is expected to begin. The function implements the algorithm described in Danielsson et al. 2001. The description of the algorithm uses the following notation:
number of observations in the original sample
number of bootstrap samples to draw
size of the bootstrap sample in the first step of the algorithm ()
th order statistic of th bootstrap sample of size ()
th order statistic of the original sample ()
Given the input sample and values of and , the steps of the algorithm are as follows:
Take bootstrap samples of size from the original sample.
Find the integer that minimizes the bootstrap estimate of the mean squared error:

Take bootstrap samples of size from the original sample.
Find the integer that minimizes the bootstrap estimate of the mean squared error:

Compute the integer , which is used for computing the cutoff point:

Set the cutoff point equal to .
The bootstrap estimate of the mean squared error is computed as

The mean squared error of th bootstrap sample is computed as

where is a control variate proposed by Danielsson et al. 2001,

and is the Hill’s estimator of the tail index (Hill 1975),

This algorithm has two tuning parameters, and . The number of bootstrap samples is chosen based on the availability of computational resources. The optimal value of is chosen such that the following ratio, , is minimized:

The SVRTUTIL_HILLCUTOFF utility function implements the preceding algorithm. It uses the grid search method to compute the optimal value of .
Type: Function
Signature: SVRTUTIL_HILLCUTOFF(n, x{*}, b, s, status)
Argument Description:
Dimension of the array x.
Input numeric array of dimension that contains the sample.
Number of bootstrap samples used to estimate the mean squared error. If b is less than 10, then a default value of 50 is used.
Approximate number of steps used to search the optimal value of in the range . If s is less than or equal to 1, then a default value of 10 is used.
Output argument that contains the status of the algorithm. If the algorithm succeeds in computing a valid cutoff point, then status is set to 0. If the algorithm fails, then status is set to 1.
Return value: The cutoff value where the right tail is estimated to start. If the size of the input sample is inadequate (), then a missing value is returned and status is set to a missing value. If the algorithm fails to estimate a valid cutoff value (status = 1), then the fifth largest value in the input sample is returned.
This function computes the specified empirical percentile given the EDF estimates.
Type: Function
Signature: SVRTUTIL_PERCENTILE(p, n, x{*}, F{*}, Ftype)
Argument Description:
Desired percentile. The value must be in the interval (0,1). The function returns the 100th percentile.
Dimension of the x and F input arrays.
Input numeric array of dimension n that contains values of the random variable observed in the sample. These values are sorted in nondecreasing order.
Input numeric array of dimension n in which each F[] contains the EDF estimate for x[]. These values must be sorted in nondecreasing order.
Type of the empirical estimate that is stored in the x and F arrays. See the section Supplying EDF Estimates to Functions and Subroutines for definition of types.
Return value: The 100th percentile of the input sample.
The method used to compute the percentile depends on the type of the EDF estimate (Ftype argument).
Smoothed empirical estimates are computed using the method described in Klugman, Panjer, and Willmot (1998). Let denote the greatest integer less than or equal to . Define and . Then the empirical percentile is defined as

This method does not work if or . If , then the function returns , which assumes that the EDF is 0 in the interval . If , then .
If , then , which assumes that the EDF is 0 in the interval . If for some value of and , then is computed as

where is a machineprecision constant as returned by the SAS function CONSTANT(’MACEPS’). If , then is computed as

If , then .
If , then , which assumes that the EDF is 0 in the interval . If for some value of and , then is computed as

where is a machineprecision constant as returned by the SAS function CONSTANT(’MACEPS’). If , then is computed as

If , then .
This subroutine computes the raw moments of a sample.
Type: Subroutine
Signature: SVRTUTIL_RAWMOMENTS(n, x{*}, nx{*}, nRaw, raw{*})
Argument Description:
Dimension of the x and nx input arrays.
Input numeric array of dimension n that contains distinct values of the random variable that are observed in the sample.
Input numeric array of dimension n in which each nx[] contains the number of observations in the sample that have the value x[].
Desired number of raw moments. The output array raw contains the first nRaw raw moments.
Output array of raw moments. The th element in the array (raw{}) contains the th raw moment, where .
Return value: Numeric array raw that contains the first nRaw raw moments. The array contains missing values if the sample has no observations (that is, if all the values in the nx array add up to zero).
This function sorts the given array of numeric values in an ascending or descending order.
Type: Subroutine
Signature: SVRTUTIL_SORT(n, x{*}, flag)
Argument Description:
Dimension of the input array x.
Numeric array that contains the values to be sorted at input. The subroutine uses the same array to return the sorted values.
A numeric value that controls the sort order. If flag is 0, then the values are sorted in an ascending order. If flag has any value other than 0, then the values are sorted in descending order.
Return value: Numeric array x, which is sorted in place (that is, the sorted array is stored in the same storage area occupied by the input array x).
You can use the following predefined functions when you define functions and subroutines using the FCMP procedure. They are summarized here for your information. See the FCMP procedure documentation in Base SAS Procedures Guide for more information.
This function computes the quantile from any continuous probability distribution by numerically inverting the CDF of that distribution. You need to specify the CDF function of the distribution, the values of its parameters, and the cumulative probability to compute the quantile.
This function computes the limited moment of order with upper limit for any continuous probability distribution. The limited moment is defined as




where and denote the PDF and the CDF of the distribution, respectively. The LIMMOMENT function uses the following alternate definition, which can be derived using integrationbyparts:

You need to specify the CDF function of the distribution, the values of its parameters, and the values of and to compute the limited moment.