Date: Fri, 11 Mar 2005 13:23:52 -0800
Reply-To: cassell.david@EPAMAIL.EPA.GOV
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject: Re: Using 'ARRAY'
In-Reply-To: <1110575095.423207f720204@mail-www2.oit.umass.edu>
Content-type: text/plain; charset=US-ASCII
Jayoung Yoon <jayoungy@ECONS.UMASS.EDU> wrote:
> I am trying to use 'array'. I understand that it would normally work
> when variables are named in the
> way such as q1h1, q1h2, q1h3, q1h4.....
>
> I was wondering if there would be a way to make 'array' work when
> variables are named like 'q1h8_1y,
> q1h8_2y, q1h8_3y, q1h8_4y....'.
Perhaps the examples you have are slightly misleading.
You can use the ARRAY statement for any list of variables.
You can have a list like this:
array veggies{4} carrot limabean rutabaga greenpepper ;
So the variables don't need to have *anything* in common,
except that they will all need to be numeric (in my example).
Or they could all be character variables, if you wanted.
The key point in whatever example you have is that SAS givs you
a special way of handling a list of variables if they happen to
look like blah1, blah2, ..., blah42 . You can use the single dash
to make SAS recognize that this is a meaningful list, with
numeric suffixes in order:
blah1 - blah42
If you have a data set which has variables in a particular order,
as you would be able to see if you use PROC CONTENTS, then you
can tell SAS to take all the variables in a sequence from that
ordering, using the double dash as the connector. So, if your
data set has (according to the order when you use PROC PRINT,
or according to the ordering listed in PROC CONTENTS) your
variables in this order (I just picked an order):
q1h8_1y q1h8_2y q1h8_3y q1h8_4y ... q1h8_42y
then you can refer to this string of variables in this way:
q1h8_1y -- q1h8_42y
HTH,
David
--
David Cassell, CSC
Cassell.David@epa.gov
Senior computing specialist
mathematical statistician