LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2008, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 29 Jul 2008 10:51:13 -0400
Reply-To:     Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject:      Re: addressing the data column as an "Array"
Comments: To: kunal <kunal.krishnan@gmail.com>
In-Reply-To:  <add95f25-9347-4e3a-b640-7bc1ce5f21b0@p10g2000prf.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Jul 29, 2008 at 10:00 AM, kunal <kunal.krishnan@gmail.com> wrote:

> Hi Muthia. Thanks a lot for the reply.But am still having a problem > here. I can load the values of the column in the temp array. But > accesing it is giving me missing values or maybe am executing it in a > wrong way. > > > data abc; > input abc @@; > cards; > 12 13 14 > ; > run; > > proc print data = abc; > run; > > data abc1; > set abc; > array a[0:2] _temporary_ ; > y=a[1]+1; > run; > > proc print data = abc1; > run; > > > Suppose i use this code. > so what am trying to do is that "y" should give me 14 > > and output should be > > no.obs abc y > 1 12 14 > 2 13 14 > 3 14 14 > > but i am getting missing values in "y" > > > One more question is that if i try using a[1] in some other data step > say: > > data marks; > set abc1; > /*abc1 contains the value of the array*/ > do i = 0 to 10; > test = a[i]; > end; > run; > > then will it retrieve the values??? > > Thanks > Kunal >

Kunal,

data abc1; set abc; array a[0:2] _temporary_ ; y=a[1]+1; run;

In the code above, a[1] will have a missing value since you have not loaded it with some value. The declaration

array a[0:2] _temporary_ ;

tells that a[ ] will have 3 elements of Numbers. At the datastep COMPILE time, SAS fills those 3 cells with missing values. Try to learn datastep DEBUGGER to know what is happening behind.

Here is the way to fill the cells of the array in the first pass (see the first do-loop).

I changed the variable name abc to x to distingush between dataset name and variable name.

data abc; input x @@; cards; 12 13 14 ; run;

In the second pass, the array elements can be used in whatever way you want. data abc1; array a[0:2] _temporary_ ; ** First pass: Fill the cells of the array; do i = 0 by 1 until(done); set abc end = done; a[i] = x; end; ** Second Pass: Use the array elements as a[1], a[0] ...; do until(eof); set abc end = eof; ** You can use some other dataset too here; y=a[1]+1; sum = x + y; output; end; drop i; run;

Once the datasep is completed (when the statement, "run;", is crossed) the array a[ ] is deleted from the memory and is not available for use.

You can have any number of do-loops within a datastep and use the array to your heart's content.

Regards,

Muthia Kachirayan


Back to: Top of message | Previous page | Main SAS-L page