Previous Page | Next Page

Functions and CALL Routines

DIF Function



Returns differences between an argument and its nth lag.
Category: Special

Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

DIF<n>(argument)


Arguments

n

specifies the number of lags.

argument

specifies a numeric constant, variable, or expression.


Details

The DIF functions, DIF1, DIF2, ..., DIF100, return the first differences between the argument and its nth lag. DIF1 can also be written as DIF. DIFn is defined as DIFn(x)=x-LAGn(x).

For details on storing and returning values from the LAGn queue, see the LAG function.


Comparisons

The function DIF2(X) is not equivalent to the second difference DIF(DIF(X)).


Examples

This example demonstrates the difference between the LAG and DIF functions.

data two;
   input X @@;
   Z=lag(x);
   D=dif(x);
   datalines;
1 2 6 4 7
;
proc print data=two;
run;

Results of the PROC PRINT step follow:

OBS        X             Z                D
 1         1             .                .
 2         2             1                1
 3         6             2                4
 4         4             6              - 2
 5         7             4                3


See Also

Function:

LAG Function

Previous Page | Next Page | Top of Page