On Wed, Jul 30, 2008 at 12:22 PM, KNuak <email@example.com> wrote:
> Does anyone know of any other method (apart from the dif and the ifn
> functions) to find
> Current minus previous values?
> I have dataset1 below and calculated dht= differences in ht(ie.current –
> previous) and dawk=differences in awk(ie. current minus previous) all by
> id below and obtained the results(output) in dataset2 below, using the ifn
> and the dif functions.
> *I want another approach to address the problem. Ie. an alternative
> method, not using the ifn and the dif functions.
> ANY ADVICE, PLEASE ON USING A DIFFERENT SAS CODE, instead of the ifn and
> the dif functions.
> used the following SAS code to obtain the output in dataset2:
> Data b;
> Set a; /*a contains dataset1*/
> By id;
> Dht=ifn(first.id,(.), dif(ht));
> id awk ht
> 29 4.3607 188
> 29 7.1803 310
> 29 9.9672 355
> 31 2.0656 112
> 31 3.1148 156
> Dataset 2:
> id awk ht dht dawk
> 29 4.3607 188 . .
> 29 7.1803 310 122 2.81967
> 29 9.9672 355 45 2.78689
> 31 2.0656 112 . .
> 31 3.1148 156 44 1.04918
Wondering why you do not want those functions?
Store the values to some temporary variables and use it for finding
if first.id then do; prev_awk = awk; prev_ht = ht; end;
else do; dht = ht - prev_ht; dawk = awk - prev_awk; end;