<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Problem with array buffer in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25492#M4459</link>
    <description>Hi:&lt;BR /&gt;
  Because you need to retain code1-code15 until you've read all the observations for a single ID, it is up to you to "refresh" or "blank out" all the code values when you know you are done with them. The point in your program where you know you are done with the code values is after you've output the new observation. So one way you could change your program would be to add a DO Loop into your test for LAST.ID:&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF LAST.ID THEN do;&lt;BR /&gt;
   OUTPUT;&lt;BR /&gt;
   do i = 1 to 15 by 1;&lt;BR /&gt;
      dd(i) = ' ';&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                              &lt;BR /&gt;
In this way, you would blank out all 15 codes and since you're on the LAST.ID, and have already done the output, then this is one way to reset the values for the DD Array (which holds code1-code15). The other way to blank out the array would be to capture the value of I when you do the output and then use that value (NUMCODE) to stop the DO Loop:&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF LAST.ID THEN do;&lt;BR /&gt;
   OUTPUT;&lt;BR /&gt;
   numcode = i;&lt;BR /&gt;
   do i = 1 to numcode by 1;&lt;BR /&gt;
      dd(i) = ' ';&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
             &lt;BR /&gt;
cynthia</description>
    <pubDate>Sun, 15 Jun 2008 12:42:12 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-06-15T12:42:12Z</dc:date>
    <item>
      <title>Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25491#M4458</link>
      <description>Hello&lt;BR /&gt;
Here is my problem with array:&lt;BR /&gt;
I have a dataset and this is how it looks:&lt;BR /&gt;
ID      Code&lt;BR /&gt;
111    AAA&lt;BR /&gt;
111    BBB&lt;BR /&gt;
111    CCC&lt;BR /&gt;
111    DDD&lt;BR /&gt;
222    EEE&lt;BR /&gt;
222    FFF&lt;BR /&gt;
&lt;BR /&gt;
lets say for a given ID we can have 15 codes(max).&lt;BR /&gt;
And Iam trying for the below format&lt;BR /&gt;
ID     Code1  Code2  Code3  Code4  Code5  Code6........Code15  I&lt;BR /&gt;
111   AAA    BBB     CCC     DDD    .          .                 .           4&lt;BR /&gt;
222   EEE    FFF      .          .          .          .                 .           2&lt;BR /&gt;
&lt;BR /&gt;
But here is what Iam getting with the below code.&lt;BR /&gt;
&lt;BR /&gt;
ID     Code1  Code2  Code3  Code4  Code5  Code6........Code15  I&lt;BR /&gt;
111   AAA    BBB     CCC     DDD    .          .                 .           4&lt;BR /&gt;
222   EEE    FFF      CCC     DDD    .          .                 .           2      &lt;BR /&gt;
&lt;BR /&gt;
Here is the code Iam using:&lt;BR /&gt;
&lt;BR /&gt;
DATA AA;&lt;BR /&gt;
SET BB;&lt;BR /&gt;
BY ID;&lt;BR /&gt;
ARRAY DD {15} $ CODE1-CODE15;&lt;BR /&gt;
RETAIN CODE1-CODE15;&lt;BR /&gt;
IF FIRST.ID THEN I=1;&lt;BR /&gt;
ELSE I+1;&lt;BR /&gt;
DD{I} = CODE;&lt;BR /&gt;
IF LAST.ID THEN OUTPUT;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
with the above details I hope you understood my problem, the buffer is not getting cleared for the second observation, though it has only 2 observations Iam still getting the CCC and DDD from previous ID.(notice the I is showing up correct count)&lt;BR /&gt;
&lt;BR /&gt;
Is there any function to clear the buffer in SAS or do we have any other way to handle this.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance&lt;BR /&gt;
Yugandar</description>
      <pubDate>Sun, 15 Jun 2008 04:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25491#M4458</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-15T04:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25492#M4459</link>
      <description>Hi:&lt;BR /&gt;
  Because you need to retain code1-code15 until you've read all the observations for a single ID, it is up to you to "refresh" or "blank out" all the code values when you know you are done with them. The point in your program where you know you are done with the code values is after you've output the new observation. So one way you could change your program would be to add a DO Loop into your test for LAST.ID:&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF LAST.ID THEN do;&lt;BR /&gt;
   OUTPUT;&lt;BR /&gt;
   do i = 1 to 15 by 1;&lt;BR /&gt;
      dd(i) = ' ';&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                              &lt;BR /&gt;
In this way, you would blank out all 15 codes and since you're on the LAST.ID, and have already done the output, then this is one way to reset the values for the DD Array (which holds code1-code15). The other way to blank out the array would be to capture the value of I when you do the output and then use that value (NUMCODE) to stop the DO Loop:&lt;BR /&gt;
[pre]&lt;BR /&gt;
IF LAST.ID THEN do;&lt;BR /&gt;
   OUTPUT;&lt;BR /&gt;
   numcode = i;&lt;BR /&gt;
   do i = 1 to numcode by 1;&lt;BR /&gt;
      dd(i) = ' ';&lt;BR /&gt;
   end;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
             &lt;BR /&gt;
cynthia</description>
      <pubDate>Sun, 15 Jun 2008 12:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25492#M4459</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-06-15T12:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25493#M4460</link>
      <description>an interesting aproach can reduce the code, by depending upon some less obvious features of a data step. &lt;BR /&gt;
The requirement here is simple, and so is the resulting code that follows:[pre]DATA AA( drop= CODE );&lt;BR /&gt;
   ARRAY DD {15} $ CODE1-CODE15;&lt;BR /&gt;
   do i=1 to 15 until( last.ID ) ;  &lt;BR /&gt;
      SET BB;&lt;BR /&gt;
      BY ID;&lt;BR /&gt;
      DD{I} = CODE;&lt;BR /&gt;
   end ;&lt;BR /&gt;
RUN; [/pre]&lt;BR /&gt;
The SET statement is &lt;I&gt;within the DO loop&lt;/I&gt; that terminates at the end of each by-group.&lt;BR /&gt;
Because the set statement is within the loop, the array elements do not need to be retained. So, the array elements will be reset to missing as each data step iteration starts&lt;BR /&gt;
On exiting the DO loop the default behaviour of a data step releases the observation without an OUTPUT statement.&lt;BR /&gt;
&lt;BR /&gt;
The technique of placing a set/merge within an explicit DO loop to take advantage of the initialisation and "temporary retention" of non-retained variables and/or FIRST-, LAST- by-group processing, while reducing the granularity of the data, has been described as a DoW loop. There have been quite a few papers describing this technique on recent SUGI and SAS Global Forums (presumeably also regional and local user groups too). &lt;A href="http://www.lexjansen.com" target="_blank"&gt;www.lexjansen.com&lt;/A&gt; provides an effective search engine.&lt;BR /&gt;
Definitely worth a read..&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Mon, 16 Jun 2008 13:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25493#M4460</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-16T13:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25494#M4461</link>
      <description>Hello&lt;BR /&gt;
Both the codes given by Cynthia and Peter has worked, thanks a lot, I have one more.&lt;BR /&gt;
&lt;BR /&gt;
I have successfully made 1 row per record and now I want to compare  a set of codes from the Code1,2,3...15 in the row.&lt;BR /&gt;
&lt;BR /&gt;
Here is my dataset looks now.&lt;BR /&gt;
&lt;BR /&gt;
ID Code1 Code2 Code3 Code4 Code5 Code6........Code15   I&lt;BR /&gt;
111 AAA BBB    CCC   DDD                                     . . .   4&lt;BR /&gt;
222 EEE FFF .                                                       . . . .  2&lt;BR /&gt;
&lt;BR /&gt;
and here is the list of codes I want to compare with and assign a flag if there is a match...&lt;BR /&gt;
Here is the code Iam using:&lt;BR /&gt;
&lt;BR /&gt;
DO I=1 TO 15 BY 1;  (or) DO I=15 TO 1 BY -1 UNTIL(I=1);&lt;BR /&gt;
IF DD{I} IN ('AAA','BBB','CCC','DDD')&lt;BR /&gt;
THEN FLAG=1; ELSE FLAG=0;&lt;BR /&gt;
END;&lt;BR /&gt;
&lt;BR /&gt;
but its just taking the first or the last observation and comparing.&lt;BR /&gt;
&lt;BR /&gt;
Can you please help me in this too...Iam a beginner in SAS arrays.&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Mon, 16 Jun 2008 20:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25494#M4461</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-16T20:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25495#M4462</link>
      <description>&amp;gt; Hello&lt;BR /&gt;
&amp;gt; Here is my problem with array:&lt;BR /&gt;
&amp;gt; I have a dataset and this is how it looks:&lt;BR /&gt;
&amp;gt; ID      Code&lt;BR /&gt;
&amp;gt; 111    AAA&lt;BR /&gt;
&amp;gt; 111    BBB&lt;BR /&gt;
&amp;gt; 111    CCC&lt;BR /&gt;
&amp;gt; 111    DDD&lt;BR /&gt;
&amp;gt; 222    EEE&lt;BR /&gt;
&amp;gt; 222    FFF&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; lets say for a given ID we can have 15 codes(max).&lt;BR /&gt;
&amp;gt; And Iam trying for the below format&lt;BR /&gt;
&amp;gt; ID     Code1  Code2  Code3  Code4  Code5&lt;BR /&gt;
&amp;gt;  Code6........Code15  I&lt;BR /&gt;
&amp;gt; 11   AAA    BBB     CCC     DDD    .          .&lt;BR /&gt;
&amp;gt;                 .           4&lt;BR /&gt;
&amp;gt; .          .          .          .&lt;BR /&gt;
&amp;gt;                 .           2&lt;BR /&gt;
&amp;gt; at Iam getting with the below code.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ID     Code1  Code2  Code3  Code4  Code5&lt;BR /&gt;
&amp;gt;  Code6........Code15  I&lt;BR /&gt;
&amp;gt; 11   AAA    BBB     CCC     DDD    .          .&lt;BR /&gt;
&amp;gt;                 .           4&lt;BR /&gt;
&amp;gt; CCC     DDD    .          .                 .&lt;BR /&gt;
&amp;gt;           2      &lt;BR /&gt;
&amp;gt; the code Iam using:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; DATA AA;&lt;BR /&gt;
&amp;gt; SET BB;&lt;BR /&gt;
&amp;gt; BY ID;&lt;BR /&gt;
&amp;gt; ARRAY DD {15} $ CODE1-CODE15;&lt;BR /&gt;
&amp;gt; RETAIN CODE1-CODE15;&lt;BR /&gt;
&amp;gt; IF FIRST.ID THEN I=1;&lt;BR /&gt;
&amp;gt; ELSE I+1;&lt;BR /&gt;
&amp;gt; DD{I} = CODE;&lt;BR /&gt;
&amp;gt; IF LAST.ID THEN OUTPUT;&lt;BR /&gt;
&amp;gt; RUN;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; with the above details I hope you understood my&lt;BR /&gt;
&amp;gt; problem, the buffer is not getting cleared for the&lt;BR /&gt;
&amp;gt; second observation, though it has only 2 observations&lt;BR /&gt;
&amp;gt; Iam still getting the CCC and DDD from previous&lt;BR /&gt;
&amp;gt; ID.(notice the I is showing up correct count)&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Is there any function to clear the buffer in SAS or&lt;BR /&gt;
&amp;gt; do we have any other way to handle this.&lt;BR /&gt;
&amp;gt;</description>
      <pubDate>Mon, 16 Jun 2008 20:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25495#M4462</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-16T20:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25496#M4463</link>
      <description>oops!!! I messed up the thread, the below is my current problem&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Hello&lt;BR /&gt;
&amp;gt; Both the codes given by Cynthia and Peter has worked,&lt;BR /&gt;
&amp;gt; thanks a lot, I have one more.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I have successfully made 1 row per record and now I&lt;BR /&gt;
&amp;gt; want to compare  a set of codes from the&lt;BR /&gt;
&amp;gt; Code1,2,3...15 in the row.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Here is my dataset looks now.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; ID Code1 Code2 Code3 Code4 Code5 Code6........Code15&lt;BR /&gt;
&amp;gt;   I&lt;BR /&gt;
&amp;gt; 1 AAA BBB    CCC   DDD&lt;BR /&gt;
&amp;gt;                                     . . .   4&lt;BR /&gt;
&amp;gt;                                 . . . .  2&lt;BR /&gt;
&amp;gt; I want to compare with and assign a flag if there is&lt;BR /&gt;
&amp;gt; a match...&lt;BR /&gt;
&amp;gt; Here is the code Iam using:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; DO I=1 TO 15 BY 1;  (or) DO I=15 TO 1 BY -1&lt;BR /&gt;
&amp;gt; UNTIL(I=1);&lt;BR /&gt;
&amp;gt; IF DD{I} IN ('AAA','BBB','CCC','DDD')&lt;BR /&gt;
&amp;gt; THEN FLAG=1; ELSE FLAG=0;&lt;BR /&gt;
&amp;gt; END;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; but its just taking the first or the last observation&lt;BR /&gt;
&amp;gt; and comparing.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Can you please help me in this too...Iam a beginner&lt;BR /&gt;
&amp;gt; in SAS arrays.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Thanks</description>
      <pubDate>Mon, 16 Jun 2008 20:14:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25496#M4463</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-16T20:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with array buffer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25497#M4464</link>
      <description>I don't understand what you expect (try explaining without using SAS code)&lt;BR /&gt;
Certainly, by having ELSE, you will only have the result of the last test performed in the loop.&lt;BR /&gt;
You may have more success if you place the FLAG = 0 ; before the DO loop and remove that else clause. Then FLAG will not be zero if at least one element of the array has a value of the list IN ('AAA','BBB','CCC','DDD')&lt;BR /&gt;
 Depending on the frequency and volume of the data going through this routine, you may want to obtain superior performance available by  bypassing the DO loop by using advanced memory management function peekC() as described in a SUGI paper by Paul Dorfman and Peter Crawford 264-29: A-P-P Advanced Data Management Functions &lt;A href="http://www2.sas.com/proceedings/sugi29/264-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/264-29.pdf&lt;/A&gt; .&lt;BR /&gt;
&lt;BR /&gt;
Good Luck&lt;BR /&gt;
&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 17 Jun 2008 08:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-array-buffer/m-p/25497#M4464</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-06-17T08:57:15Z</dc:date>
    </item>
  </channel>
</rss>

