Date: Tue, 22 Jul 2008 21:11:24 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Subject: Re: SAS code for current minus previous variable
Content-Type: text/plain; charset=ISO-8859-1
On Tue, 22 Jul 2008 17:20:28 -0500, data _null_, <datanull@GMAIL.COM> wrote:
>This might help you. Consult the documentation for any statements you
>don't recognize.
>
>data pigs;
> input obs pigid:$3. age predwt;
> cards;
>1 101 0 17.2 0 0
>2 101 1 24.5 7.3 1.04
>3 101 2 31.7 7.2 1.03
>4 101 3 39.6 7.9 1.13
>5 101 4 49.8 10.2 1.46
>6 107 0 17.2 0 0
>7 107 1 24.5 7.3 1.04
>;;;;
> run;
>data work.pigs;
> do until(last.pigid);
> set pigs;
> by pigid;
> dif = ifn(first.pigid,0,dif(predwt));
> dif7 = dif/7;
> output;
> end;
> run;
>proc print;
> run;
>
Three suggestons:
1. Eliminate the DO, OUTPUT, and END statements. It should not affect the
results.
2. Use a different name for the output data set, unless you want the input
data set to go away.
3. Nothing (absence of a data point) and zero are not the same. Chances are
that subsequent processing will be simpler and/or more accurate if the zero
is replaced by a dot (missing value).
>On 7/22/08, KNuak <asom77@hotmail.com> wrote:
>> I have 30 different pigids(only 2 shown) with their ids (col 2), ages
>> (col3) and the predicted weights(col4) shown below.
>> I want to use SAS to find the weight gain per week (col 5) and the mean
>> predicted weight gain(col6).
>> To find the wt gain/week(col 5) ,it is the current predwt(col4) minus the
>> previous predwt(still col4).
>> For instance for obs 1, the wtgain(col5) is the current(present) predwt
>> ie. 17.2(in col4) minus previous(there was nothing ie. 0) yielding wt gain
>> of 0.
>> To find the meanpredwtgain(col 6), it is col 5/7.
>> For obs 1, the mean predicted wt gain(col6) is col 5/7 ie. 0/7=0 etc.
>> For obs 2, the wtgain(col5) is the current(present) predwt in col 4 ie.
>> 24.5 minus previous( 17.2 still in col 4) yielding wt gain of 7.3(col5).
>> For obs 2, the mean predicted wt gain(col6) is col 5/7 ie. 7.3/7=1.04
>> *COULD SOMEONE HELP ME WITH THE SAS CODE TO DO THE WORK IN COL 5 ie.
>> find the wtgain(current predwt �previous predwt) for each pigid(30 of
>> them) and COL 6 ie.to find the
>> Mean predwtgain for each pigid. The original dataset is only up to col4.
>> Cols 5 & 6 need to be created.
>> Col1 col2 col3 col4 col5 col6
>> 1 101 0 17.2 0 0
>> 2 101 1 24.5 7.3 1.04
>> 3 101 2 31.7 7.2 1.03
>> 4 101 3 39.6 7.9 1.13
>> 5 101 4 49.8 10.2 1.46
>> 6 107 0 17.2 0 0
>> 7 107 1 24.5 7.3 1.04
>>
>> Col1=obs, col 2=ids, col 3=ages, col 4=predwt , col 5=wtgain per week,
>> col6=mean predwt gain=col5/7;
>>
|