```Date: Tue, 29 Jul 2003 11:46:03 -0700 Reply-To: Dale McLerran Sender: "SAS(r) Discussion" From: Dale McLerran Subject: Re: array processing In-Reply-To: Content-Type: text/plain; charset=us-ascii A simple datastep approach that works similarly to Prasad's SQL solution would be as follows: data two; set one(keep=vara rename=(vara=newvar)) one(keep=varb rename=(varb=newvar)) one(keep=varc rename=(varc=newvar)); run; An array based solution would have to load all of the data into memory in a two dimensional array which is indexed on variable and row number. When all data have been read, then loop back through the data by row number within variable index. Thus, we could write the following: data two; set one end=lastrec; array var_in {3} vara varb varc; array all_dat {3,10000} _temporary_; /* Store observed values into _n_th row of all_dat array */ do i=1 to 3; all_dat{i,_n_}=var_in{i}; end; /* Once we have read all the data, then loop over rows */ /* within variable indexes and write the stored value. */ if lastrec then do; do i=1 to 3; do j=1 to _n_; newvar = all_dat{i,j}; output; end; end; end; keep newvar; run; Hope these help, Dale --- Prasad S Ravi wrote: > Carey: > > If your friend does not care for a PROC SQL solution which may be > less > efficient than the array solutions > here is another way, assuming the TYPE and LENGTH of the variables > are the > same: > > data one; > vara=1; > varb=2; > varc=3; > run; > > proc sql; > create table two as > select vara as newvar > from one > union > select varb as newvar > from one > union > select varc as newvar > from one; > quit; > run; > proc print data=two; > run; > > output: > > Obs newvar > 1 1 > 2 2 > 3 3 > > > Prasad Ravi > > > > > > > Carey Smoak > SAS-L@LISTSERV.UGA.EDU > M> cc: > Sent by: "SAS(r) Subject: array > processing > Discussion" > DU> > > > 07/29/2003 09:34 AM > Please respond to > Carey Smoak > > > > > > > Hi SAS-Lers, > > I am submitting this question for a co-worker of mine. > > Suppose you have a dataset that has 10,000 observations and three > variable (VarA, VarB and VarC). Suppose that you want to create a > new > dataset with a single variable that appends VarB and then VarC to > VarA. This new dataset would have 30,000 observations. Is there a > way to use array processing to accomplish this task? My co-worker > has > made several attempts at using arrays, but has not been successful. > > Of course, this can be done with several data steps, but my co-worker > is trying to find a more efficient solution using arrays. > > Regards, > > Carey G. Smoak > Roche Molecular Systems, Inc. ===== --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 --------------------------------------- __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com ```

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