Date: Fri, 12 Nov 2004 10:38:05 -0600
Reply-To: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject: Re: incrementing the value
Content-Type: text/plain; charset="us-ascii"
An,
cnt=sum(cnt,1);
Or
Cnt = cnt + 1;
Is a assignment statement and SAS requires them to be in a retain
statement if you do not want them reset to missing with each iteration
of a data step.
Cnt + 1;
Is a speacial sum statement in which it sums but also it has a implied
retain.
Now on to bigger problems:
>My understanding is in a set statement variables are reset to missing
at the beginning of the >iteration. In the second case even without
retain cnt is incremented.
No no no.....Trust me Jack Hamilton spanked me for messing this one up
too, but I learned so it was well worth it.
Set statement variables ??? If you mean variables from a SAS data set
then read on: any variable from a sas dataset, temoporary , and
automatic variables are automatically retained and therefore a retain
statement with these variables does nothing.
Variables that come from a input statement, assignment statement, and
possibly a few (aurguably mind you) functions are not retained
automatically and therefore need to have a retain statement if you wish
them not to be reset to missing.
HTH
Toby Dunn
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of An
Am
Sent: Friday, November 12, 2004 10:09 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: incrementing the value
Hi,
Here is the sample dataset.
data a;
input name $;
datalines;
john
joseph
peter
;
Here retain statement is used. But if you don't use retain statement
then cnt is not incrementing. data b; retain cnt; set a; cnt=sum(cnt,1);
run;
Here if you just use cnt+1.
data c;
set a;
cnt+1;
run;
My understanding is in a set statement variables are reset to missing at
the beginning of the iteration. In the second case even without retain
cnt is incremented.
Can you explain please.
Thanks,
Anbu