Date: Tue, 9 Aug 2005 16:15:55 -0700
Reply-To: David L Cassell <davidlcassell@MSN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: David L Cassell <davidlcassell@MSN.COM>
Subject: Re: macro array questions
In-Reply-To: <MC9-F3QqotSJpjK4LRN00208916@mc9-f3.hotmail.com>
Content-Type: text/plain; format=flowed
chen4sas@YAHOO.COM wrote:
>I have a dataset D1 that has one variable 'a'. In
>dataset D2, I want to create an array of macro
>variables that have the value of 'a'. The macros will
>be called later in the same data step.
>
>I have been trying all the afternoon. Below is one of
>the unsuccessful attemps. I appreciate if you could
>give me any clue.
>
>data D1;
> input a;
>cards;
>1
>2
>3
>;
>
>data D2;
> set d1;
> array marray[3];
> do i=1 to 3;
> marray[i]=symget(a);
> end;
First off, i don't think you want to use macro variables here. At all.
Second, trying to create a macro variable and then call it back in
the same data step, even using SYMGET(), is probably not a
good idea. (There are good examples of this on SAS-L, but I
don't think this is one of them.)
Third, you cannot call a macro variable (even with SYMGET() )
until after you have created it, and a macro variable is nothing
like a variable in a data set.
Fourth, I would be happier if you used the "RUN;" statement at
the end of your steps.
Why don't you just read the values of data set D1 into an
array, and use the array, with no macro variable instantiation
at all?
data D2;
array marray{3};
do _n_ = 1 by 1 until(eof);
set D1 end=eof;
marray{_n_} = a;
end;
/* now do whatever processing you wanted using the array */
run;
An alternative is to use PROC TRANSPOSE to turn your data set
D1 into a single row and read that into the array all at once,
at the beginning of the data step.
There may be several other alternatives, given what you actually
want to do with your data. You might benefit from looking at
using SAS formats for table lookup, as well as studying what can
be done with hashes in the SAS 9 data step.
I can't give you much better advice when you haven't explained
the actual task involved.
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/