Date: Mon, 14 Dec 2009 08:28:27 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: SAS dynamic arrays
In-Reply-To: <20091214133122.10436wcl9ieigpp6@webmail.nfit.au.dk>
Content-Type: text/plain; charset=ISO-8859-1
No reason you would need to dimension it at all. SAS is quite smart and can
figure it out for you on the fly.
array sampled sampled:;
will take every variable starting with 'sampled' and something after it.
-Joe
On Mon, Dec 14, 2009 at 6:31 AM, HÃ¥kan Lane <hlane@cls.dk> wrote:
> I would like to implement an array the size of which is not known a
> priori. Instead of declaring an implicit value for the number of
> elements, I wish to find this value from a variable. This can be done
> in other languages including Fortran.
>
> My attempt to code this as shown below fails.
>
> DATA libout.pdata;
> SET cpr;
> byear=aar-alder;
> numyears=&slutaar-&startaar+1;
> Array sampled{numyears} sampled&startaar - sampled&slutaar;
> sampled{aar}=1;
> DROP alder numyears;
> IF last.pnr THEN output;
> ELSE DO;
> END;
> RUN;
>
> The idea is to replace a structure with one record every year that a
> person was in our records with their age so an array with a 1 if they
> were in and 0 if they weren't. The age (alder from above) is
> represented with a birthyear. This would quite obviously save a lot of
> redundant data. The issue is that we might run the program with
> different start and end years. That is why it would be better for them
> to be external constants.
>
> Thanks in advance.
>
> Regards,
>
> Håkan Lane
>
|