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 (August 2003, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 14 Aug 2003 19:49:02 +0000
Reply-To:     sashole@bellsouth.net
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Paul Dorfman <paul_dorfman@HOTMAIL.COM>
Subject:      Re: Define an array with previously existing variables?
Comments: To: iced_phoenix@YAHOO.COM
Content-Type: text/plain; format=flowed

Matt,

Somewhere in the docs it is said that an array lasts only for the duration of a Data step. So, no array in one Data step has anything to do with any array in another Data step, which is, if you come to think of it, is only natural, because two Data steps are two completely separate, separately compiled and executed programs, whose memories exist only for their durations. Since arrays are memory-based structures, they are entirely suspended at the end of a step.

A more interesing questions would be:

1) Can two arrays in the *same* step share the same elementsbe defined with the same elements?

The answer is "yes, as long as the variables in teh same array are of the same data type", i.e. numeric or character, e.g.

data _null_ ; retain a 'a' b 'bb' c 'ccc' g 'gggg' ; retain one 1 two 22 three 333 four 4444 ; array c1 (*) $ a b c ; array c2 (*) $ c b g ; array n1 (*) one two three ; array n2 (*) four one three ; run ;

2) Can the same variable be present in the same array?

There is no reason why not. In fact, this is invaluable because it allows one to use an array to group different variables into the same category, for example

data _null_ ; array dd d1 - d7 ; input dd (*) ; array ww wkend wkday wkday wkday wkday wkday wkend ; do over ww ; ww ++ dd ; end ; put wkend= wkday= ; cards ; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 run ; _________________ wkend=2 wkday=5 wkend=4 wkday=10 wkend=6 wkday=15

Kind regards, =============== Paul M. Dorfman Jacksonville, FL ===============

>From: m n <iced_phoenix@YAHOO.COM> > >Dear SAS-L, > >I realize this is a simple question, though I can't find an explicit answer >to it in the SAS V8 docs. Is it legal in Base SAS to define an array >with previously existing variables? For instance, > >data test; > input a b c; > cards; > 1 2 3 > 4 5 6 > 7 8 9 > ; >run; > >data _null_; > array one {*} a b c; > set test; >run; > >data _null_; > set test; > array two {*} a b c; >run; > >Are both _null_ data steps legal? Running these steps suggest that they >are, >but I can't find documentation to back up that result. > >Thanks for your help, >Matt

_________________________________________________________________ Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail


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