Date: Wed, 3 Dec 2008 11:29:36 -0500
Reply-To: Mike Rhoads <RHOADSM1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mike Rhoads <RHOADSM1@WESTAT.COM>
Subject: Re: Implicit Arrays and DO OVER
In-Reply-To: <482249F865060740AE33815802042D2F0164448B@LTA3VS012.ees.hhs.gov>
Content-Type: text/plain; charset="us-ascii"
I have to think this will turn up in Art Carpenter's next "Programming for Job Security" paper ...
;-)
Mike Rhoads
Westat
RhoadsM1@Westat.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Fehd, Ronald J. (CDC/CCHIS/NCPHI)
Sent: Wednesday, December 03, 2008 10:52 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Implicit Arrays and DO OVER
thank you
I sit corrected.
I stick w/my point in the context of the thread:
of neither using nor encouraging deprecated usage
_temporary_ may indeed be used as
a user-defined temporary variable name
but I would certainly not recommend its usage that way
since it is an array statement keyword/option.
Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
> -----Original Message-----
> From: ./ ADD NAME=Data _null_, [mailto:iebupdte@gmail.com]
> Sent: Wednesday, December 03, 2008 10:46 AM
> To: Fehd, Ronald J. (CDC/CCHIS/NCPHI)
> Cc: SAS-L@listserv.uga.edu
> Subject: Re: Implicit Arrays and DO OVER
>
> Incorrect? In that context it is a variable name. While it may not
> produce the expected result it is not incorrect. Consider the
> following.
>
> 96 data _null_;
> 97 array a[4] a1-a3 _temporary_;
> 98 retain a 8;
> 99 put _all_;
> 100 run;
>
> a1=8 a2=8 a3=8 _temporary_=8 _ERROR_=0 _N_=1
>
> 101 data _null_;
> 102 array _temporary_[4] _temporary_ (4*9);
> 103 put _temporary_[3]=;
> 104 run;
>
> _temporary_[3]=9
>
>
> On 12/3/08, Fehd, Ronald J. (CDC/CCHIS/NCPHI) <rjf2@cdc.gov> wrote:
> > My point was you(plural)
> > were using the keyword _temporary_
> > incorrectly.
> >
> > > -----Original Message-----
> > > From: ./ ADD NAME=Data _null_, [mailto:iebupdte@gmail.com]
> > > Sent: Wednesday, December 03, 2008 10:16 AM
> > > To: Fehd, Ronald J. (CDC/CCHIS/NCPHI)
> > > Cc: SAS-L@listserv.uga.edu
> > > Subject: Re: Implicit Arrays and DO OVER
> > >
> > > I think you need to read this tread more closely. This thread has
> > > nothing to do with temporary arrays.
> > >
> > > It is about implicit array declaration and reference. I used
> > > _TEMPORARY_ as was done by the OP because I wanted to show that in
> > > this context _TEMPORARY_ becomes a variable and has no
> special action.
> > >
> > > On 12/3/08, Fehd, Ronald J. (CDC/CCHIS/NCPHI)
> <rjf2@cdc.gov> wrote:
> > > > I think a quiet session of RTFM is appropriate here
> > > > in order to make sure we understand exactly what
> > > > _temporary_ is supposed to do.
> > > >
> > > > From the OnLine Doc:
> > > > arrays
> > > > assigning initial values to elements
> > > >
> > > > page title:
> > > > Array Processing
> > > >
> > > > Examples of Array Processing
> > > >
> > > > ....
> > > >
> > > > Example 3: Creating an Array for Temporary Use in the
> > > Current DATA Step
> > > >
> > > > When elements of an array are constants that are needed
> only for the
> > > > duration of the DATA step, you can omit variables from an
> > > array group
> > > > and instead use temporary array elements. You refer to
> > > temporary data
> > > > elements by the array name and dimension. Although they
> behave like
> > > > variables, temporary array elements do not have names, and
> > > they do not
> > > > appear in the output data set. Temporary array elements are
> > > > automatically retained, instead of being reset to missing at the
> > > > beginning of the next iteration of the DATA step.
> > > >
> > > > To create a temporary array, use the _TEMPORARY_ argument.
> > > The following
> > > > example creates a temporary array named TEST:
> > > >
> > > > options nodate pageno=1 linesize=80 pagesize=60;
> > > >
> > > > data score2(drop=i);
> > > > array test{3} _temporary_ (90 80 70);
> > > >
> > > >
> > > > > -----Original Message-----
> > > > > From: owner-sas-l@listserv.uga.edu
> > > > > [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of ./ ADD
> > > > > NAME=Data _null_,
> > > > > Sent: Wednesday, December 03, 2008 4:52 AM
> > > > > To: Akshaya Nathilvar
> > > > > Cc: SAS-L@listserv.uga.edu
> > > > > Subject: Implicit Arrays and DO OVER
> > > > >
> > > > > On 12/2/08, Akshaya Nathilvar
> <akshaya.nathilvar@gmail.com> wrote:
> > > > > > I take that back, looks like adding _TEMPORARY_ keyword
> > > to the array
> > > > > > statement avoids the OUT OF RANGE error message:
> > > > > > For example:
> > > > > >
> > > > > > Data have;
> > > > > > input ID $ A1 A2 A3 B1 B2 B3 B4 b5 ;
> > > > > > cards;
> > > > > > QQ 1 2 3 5 2 4 9 10
> > > > > > GG 3 8 3 6 7 4 9 10
> > > > > > WW 4 5 6 6 1 8 9 10
> > > > > > ;
> > > > > >
> > > > > > Data want;
> > > > > > set have;
> > > > > > array abc a1-a3 _temporary_ _temporary_;
> > > > > > array xyz b1-b5;
> > > > > > do over abc;
> > > > > > A=abc;
> > > > > > B=xyz;
> > > > > > output;
> > > > > > end;
> > > > > > keep ID A B;
> > > > > > Run;
> > > > > >
> > > > > > Akshaya!
> > > > >
> > > > >
> > > > > To me this statement implies some misunderstanding of
> > > implicit array
> > > > > declarations and reference.
> > > > >
> > > > > ARRAY arrayname(index variable) <list of names>;
> > > > >
> > > > > The default index variable is _I_.
> > > > >
> > > > > To reference this type of array you first set the value
> > > of the index
> > > > > variable and then use the array name.
> > > > >
> > > > > array imp a b c;
> > > > > _i_=2;
> > > > > imp = 100;
> > > > > x = imp;
> > > > >
> > > > > The value of variable b, array element 2 is assigned the
> > > value 100.
> > > > > Then x is given the same value.
> > > > >
> > > > > DO OVER is simply short hand for
> > > > >
> > > > > DO indexVariable = 1 to dim(array);
> > > > >
> > > > > When DO OVER was "king" I don't recall there being a DIM
> > > function so
> > > > > you can see how the syntax was quite useful.
> > > > >
> > > > > It should also be noted that the elements of an implicit
> > > array can be
> > > > > a list of implicit arrays. Arrays of arrays.
> > > > >
> > > > >
> > > > > Akshaya's data step modified slightly to show the
> > > definitions of the
> > > > > implicit elements more explicitly. _TEMPORARY_ is a
> variable name
> > > > > when used in this context.
> > > > >
> > > > > Data want;
> > > > > set have;
> > > > > array abc(_i_) a1-a3 _temporary_ _temporary_;
> > > > > array xyz(_i_) b1-b5;
> > > > >
> > > > > *do over abc;
> > > > > do _i_ = 1 to dim(abc);
> > > > > A=abc;
> > > > > B=xyz;
> > > > > output;
> > > > > end;
> > > > > keep ID A B;
> > > > > put _all_;
> > > > > Run;
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>
>
|