```Date: Fri, 10 May 2002 11:55:23 -0700 Reply-To: Glenn Heagerty Sender: "SAS(r) Discussion" From: Glenn Heagerty Organization: Consumer Solutions Subject: Re: shifting elements in an array Comments: To: "Schulingkamp, Michael E" Content-Type: multipart/alternative; Hi Mike, Here's a data step that used the first m elements of an array with n elements, shifted the n-m elements, and set the remaining m elements to missing. It was tested with n=10 and m=1,5,6,9, and 10. I hope you find it helpful. Thanks, Glenn %let n=10; %let m=6; data a; array temp{&n} temp1-temp&n; do i = 1 to &n; /** Load sample array **/ temp{i} = i; end; j = sum(of temp1-temp&m); /** Do someting with first m elements **/ do i = &m+1 to &n; /** Shift elements m+1 to n to first n-m positions**/ inew = i - &m; /** and set m+1 to n elements to missing **/ temp{inew} = temp{i}; temp{i} = .; if i = 10 then do j = inew + 1 to &m; /** set m - (n - m) positions to missing**/ temp{j} = .; end; end; run; >>>>>>>>>>>>>>>>>>>>Mike wrote: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I'm looking for ideas on how to shift elements in an array. I have the following array array temp(10) temp1 - temp10 and each element has a numeric value. I want to use the first N elements of the array (temp1 -tempN) and then shift the values in temp(N+1) - temp10 to the left filling the positions starting at temp1 through temp(10-N). Basically, a FIFO array. Any ideas? Thanks in advance, Mike [text/html] ```

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