Date: Wed, 30 Jul 2008 13:25:21 -0400
Reply-To: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject: Re: current minus previous value/another approach with SAS?
In-Reply-To: <200807301622.m6UB5H9C021452@malibu.cc.uga.edu>
Content-Type: text/plain; charset=WINDOWS-1252
On Wed, Jul 30, 2008 at 12:22 PM, KNuak <asom77@hotmail.com> wrote:
> Hello,
> 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));
> Dawk=ifn(first.id,(.),dif(awk));
> Run;
>
> Dataset1:
> 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
differences.
data need;
do until(last.id);
set have;
by id;
if first.id then do; prev_awk = awk; prev_ht = ht; end;
else do; dht = ht - prev_ht; dawk = awk - prev_awk; end;
output;
end;
drop prev:;
run;
Muthia Kachirayan
|