DataFlux Data Management Studio 2.6: User Guide
You can use a custom metric to perform a calculation for one or more fields when there is no predefined DataFlux expression for that operation. For example, you could create a metric that calculates the average value for a sales field in all records from a particular state. Perform the following steps:
A custom metric is a reusable object that specifies a user-defined DataFlux expression. You must have a detailed understanding of DataFlux Expression Language in order to create a custom metric. For more information, see the DataFlux Expression Language Reference Guide.
You can specify three blocks of code for a custom metric: a pre-expression, an expression, and a post-expression. The following DataFlux expression code will calculate the average value for a sales field in all records from a particular state, North Carolina (NC).
Pre-expression
public hidden integer total_sales
public hidden integer row_count
public integer `AVERAGE_SALES`
total_sales = 0
row_count = 0
`AVERAGE_SALES` = 0
Expression
if `STATE` == 'NC' then
begin
total_sales = total_sales + `SALES`
row_count = row_count + 1
end
Post-expression
`AVERAGE_SALES` = total_sales / row_count
Note the input fields and output fields that are specified in your expression. You will need this information later. In the previous code, the input fields are SALES and STATE, and the output field is AVERAGE_SALES.
You have created a new custom metric. You are now ready to use the metric in a profile or data job.
For an example of how custom metrics can be used in a profile, see Apply Custom Metrics. For an example of how custom metrics can be used in a data job, see Using the Execute Custom Metric Node.
Documentation Feedback: yourturn@sas.com
|
Doc ID: dfU_T_BusRule_CreateMetric.html |