The simplest way to calculate a temporary field is to define it in a report request using the COMPUTE command. The temporary fields you create using the COMPUTE command are not real fields in the data source. They only exist for the request in which you create them.
The basic format of a COMPUTE command is:
COMPUTE field/format=expression;
In this structure, field represents the name you give the temporary field you are creating. You define the field format with a slash (/) and the desired format, which describes the type and length of data in a field. By default, the numeric format D12.2 is assigned to temporary fields, but it is good coding practice to always provide a format. On the right side of the equation, expression is a formula you specify that indicates how to calculate values for the new field.
When you write a COMPUTE command, keep the following rules in mind:
To illustrate how you create a new field from existing data, calculate the difference between gross pay and the amount taken out in deductions for each employee and store it in a new field called DIFF.
The data you use is stored in the fields GROSS and DED_AMT. The formula for calculating the new field value is simply:
DIFF = GROSS - DED_AMT;
Issue the following request:
TABLE FILE EMPLOYEE SUM GROSS AND DED_AMT AS 'DEDUCTIONS' COMPUTE DIFF/D12.2=GROSS - DED_AMT; AS 'NET,INCOME' BY EMP_ID END
Run the request. The output is:
You have just used a simple expression to create a new field in a report. You can write many kinds of expressions, depending on the kind of temporary field you want to create.
WebFOCUS | |
Feedback |