<?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: Why dim(array)= number of elements +1 and auto popup at the result? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713667#M220207</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;Thank you very much for your straightforward answer. I benefit a lot from reading your suggestion. However, I have two points that I am confused about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Regarding the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 by 1 until (i=dim(delwords));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;whether we can also write&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to dim(delwords) by 1 until (i=dim(delwords));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because I read examples&amp;nbsp; from other material is that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=... to... by...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know it is a very novice question but I am quite prudent regarding code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Regarding the extra part of UNTIL clause, do you mean that while we delete one observation because the ENAME of this observation contains a specific word in the array, we do not need to go through all specific words after this word for this observation because this observation was deleted already? If it is the case, I totally agree with you, and thank you very much for the code enhancement.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Sun, 24 Jan 2021 08:20:08 GMT</pubDate>
    <dc:creator>Phil_NZ</dc:creator>
    <dc:date>2021-01-24T08:20:08Z</dc:date>
    <item>
      <title>Why dim(array)= number of elements +1 and auto popup at the result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713661#M220202</link>
      <description>&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Recently I built a code to filter my data, and I also use an array to delete some observations containing some specific words. The code is as below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS MPRINT;
data arg_merge2;
  set 'C:\Users\pnguyen\Desktop\arg_merge2';

run;

data screen12348911;
   set arg_merge2;
   if TYPE_1 = "EQ" 
   /*SCREEN 1*/
   and INDC3 not in ('UTILS', 'BANKS', 'FINSV', 'RLEST', 'INSUR')
   /*SCREEN 2*/
   and MAJOR="Y" 
   /*SCREEN 3*/
   and substr(GEOGN,1,3)= "ARG"
   /*SCREEN 4*/
   /*PUT 
   substr(GEOGN,1,3)=short_fn
   IN MACRO*/
   and 
   s3 ge 0
   /*SCREEN 8*/
   and
   s21 ge 0 and s22 ge 0
   /*SCREEN 9*/
   and
   s2 ge 0
   /*SCREEN 11*/

;
run;

data screen123489116;
/*SCREEN 6*/
set screen12348911;
 array delwords {84} $ 15 _temporary_ ('DUPLICATE', 'DUPL', 'DUP', 'DUPE','DULP', 'DUPLI',
'1000DUPL','XSQ','XET','ADR','GDR','PREFERRED','PF','PFD','PREF',"'PF'",'WARRANT','WARRANTS',
'WTS','WTS2','WARRT','DEB','DB','DCB','DEBT','DEBENTURES','DEBENTURE','RLST IT','INVESTMENT TRUST',
'INV TST','UNIT TRUST','UNT TST','TRUST UNITS','TST UNITS','TRUST UNIT','TST UNIT','UT','IT.',
'IT','500','BOND','DEFER','DEP','DEPY','ELKS','ETF','FUND','FD','IDX','INDEX','LP','MIPS','MITS',
'MITT','MPS','NIKKEI','NOTE','PERQS','PINES','PRTF','PTNS','PTSHP','QUIBS','QUIDS','RATE','RCPTS',
'RECEIPTS','REIT','RETUR','SCORE','SPDR','STRYPES','TOPRS','UNIT','UNT',
'UTS','WTS','XXXXX','YIELD','YLD','EXPIRED','EXPD','EXPIRY','EXPY');
do i= 1 to dim(delwords);
 if findw(ENAME,delwords[i],'','eir') &amp;gt;0 then delete;
end;
run;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want to highlight here is screen 6, so there are 84 elements in array "del words" that I want to delete. However, the result "screen123489116" is as below:&lt;/P&gt;
&lt;DIV id="tinyMceEditorMy97_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditorMy97_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;There are two things here that surprised me:&lt;/P&gt;
&lt;P&gt;1. Why "I" automatically pop up in my result?&lt;/P&gt;
&lt;P&gt;2. And if it pops up like that, it should be 84 rather than 85?&lt;/P&gt;
&lt;P&gt;3. And whether "ge" in screen 11 equals to "greater than or equal to" ? Can I use "&amp;gt;=" instead of "ge" as the definition of the operator as the link following?&lt;/P&gt;
&lt;P&gt;(&lt;A href="https://v8doc.sas.com/sashtml/lgref/z0208245.htm#:~:text=The%20result%20of%20a%20comparison,versions%20of%20the%20SAS%20System" target="_blank"&gt;https://v8doc.sas.com/sashtml/lgref/z0208245.htm#:~:text=The%20result%20of%20a%20comparison,versions%20of%20the%20SAS%20System&lt;/A&gt;. )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks and warmest regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorMy97_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 24 Jan 2021 06:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713661#M220202</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-24T06:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Why dim(array)= number of elements +1 and auto popup at the result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713664#M220204</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Users,&lt;/P&gt;
&lt;P&gt;There are two things here that surprised me:&lt;/P&gt;
&lt;P&gt;1. Why "I" automatically pop up in my result?&lt;/P&gt;
&lt;P&gt;2. And if it pops up like that, it should be 84 rather than 85?&lt;/P&gt;
&lt;P&gt;3. And whether "ge" in screen 11 equals to "greater than or equal to" ? Can I use "&amp;gt;=" instead of "ge" as the definition of the operator as the link following?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;OL&gt;
&lt;LI&gt;"i" is a new variable that you created as the iterator value in the do loop.&amp;nbsp; To SAS, it's just another variable you created, to be automatically kept in the output.&amp;nbsp; Use a "&lt;EM&gt;&lt;STRONG&gt;(drop=i)&lt;/STRONG&gt;&lt;/EM&gt;" parameter in your DATA statement to get rid of it.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;YOU have&amp;nbsp;&lt;LI-CODE lang="sas"&gt;do i= 1 to dim(delwords);
 if findw(ENAME,delwords[i],'','eir') &amp;gt;0 then delete;
end;​&lt;/LI-CODE&gt;
&lt;P&gt;Your DO loop increments i by 1 at the end of each iteration.&amp;nbsp; The last complete iteration in your case is 84.&amp;nbsp; The DO loop increments it to 85.&amp;nbsp; The loop returns to the top as normal, but then finds that i is out of range, and the loop stops.&lt;BR /&gt;&lt;BR /&gt;Run this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 84;              end;  put i=;
  do j=1 to 84 until (j=84); end;  put j=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both of the loop have 84 complete iterations.&amp;nbsp; But j never gets to 85, while i does.&amp;nbsp; That's because the "until" condition in the second loop is evaluated at the end of the loop, before incrementing the loop iterator.&amp;nbsp; When the until condition is met, no further incrementing occurs.&lt;BR /&gt;&lt;BR /&gt;Edited additional comment: I guess you could&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 by 1 until (i=dim(delwords));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but there's really no point.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;This is a question best answered by giving it a try.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And speaking of the UNTIL clause, I should have added that you can make your loop much more efficient.&amp;nbsp; There is no need to go through the 2nd through 84th iterations, if the 1st iteration finds a delete-word.&amp;nbsp; You want to escape the do loop the first time you find a delete-word.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  do i= 1 to dim(delwords) until (f&amp;gt;0);
   f=findw(ENAME,delwords[i],'','eir');
  end;
  if f&amp;gt;0 then delete;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If all 84 iterations fail to find a delete-word, then f is a zero (84 times, but the only time you test it is the last).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 07:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713664#M220204</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-24T07:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why dim(array)= number of elements +1 and auto popup at the result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713667#M220207</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;
&lt;P&gt;Thank you very much for your straightforward answer. I benefit a lot from reading your suggestion. However, I have two points that I am confused about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Regarding the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 by 1 until (i=dim(delwords));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;whether we can also write&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to dim(delwords) by 1 until (i=dim(delwords));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because I read examples&amp;nbsp; from other material is that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=... to... by...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know it is a very novice question but I am quite prudent regarding code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Regarding the extra part of UNTIL clause, do you mean that while we delete one observation because the ENAME of this observation contains a specific word in the array, we do not need to go through all specific words after this word for this observation because this observation was deleted already? If it is the case, I totally agree with you, and thank you very much for the code enhancement.&lt;/P&gt;
&lt;DIV id="eJOY__extension_root" class="eJOY__extension_root_class" style="all: unset;"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 24 Jan 2021 08:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713667#M220207</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-24T08:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why dim(array)= number of elements +1 and auto popup at the result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713668#M220208</link>
      <description>&lt;P&gt;1. ge is short for: greater equal&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gt is short for greater than&lt;/P&gt;
&lt;P&gt;2. You can write your test without a loop, like this:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;if prxmatch("/\b('DUPLICATE|DUPL|DUP|DUPE|DULP|DUPLI|1000DUPL|XSQ|XET|ADR|GDR|PREFERRED|PFD?|PREF|PFD?|'PF'|WARRANTS?|WTS2|WARRT|DEB|DB|DCB|DEBT|DEBENTURES?|RLST IT|INVESTMENT TRUST|INV TST|UNI?T|UTS|UNIT TRUST|UNT TST|T(RU)?ST UNITS?|UT|IT\.|IT|500|BOND|DEFER|DEP|DEPY|ELKS|ETF|FUND|FD|IDX|INDEX|LP|MIPS|MITS|MITT|MPS|NIKKEI|NOTE|PERQS|PINES|PRTF|PTNS|PTSHP|QUIBS|QUIDS|RATE|RCPTS|RECEIPTS|REIT|RETUR|SCORE|SPDR|STRYPES|TOPRS|WTS|XXXXX|YIELD|YLD|EXPIRED|EXPD|EXPIRY|EXPY)\b/i",ENAME);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jan 2021 08:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713668#M220208</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-24T08:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why dim(array)= number of elements +1 and auto popup at the result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713669#M220209</link>
      <description>Regarding the second point, I mean, if what you intend to do is similar to what I understand, so there is no difference between your code and my code previously. Because previously, if a specific word in the array was found in an observation of ENAME, then we delete this observation immediately, then I think the program will not continue with the rest of the list of words for this deleted observation? &lt;BR /&gt;Please correct me if I understand you improperly!</description>
      <pubDate>Sun, 24 Jan 2021 08:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713669#M220209</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2021-01-24T08:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why dim(array)= number of elements +1 and auto popup at the result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713787#M220266</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212695"&gt;@Phil_NZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Regarding the second point, I mean, if what you intend to do is similar to what I understand, so there is no difference between your code and my code previously. Because previously, if a specific word in the array was found in an observation of ENAME, then we delete this observation immediately, then I think the program will not continue with the rest of the list of words for this deleted observation? &lt;BR /&gt;Please correct me if I understand you improperly!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are correct.&amp;nbsp; The loop will stop at the DELETE statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 00:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-dim-array-number-of-elements-1-and-auto-popup-at-the-result/m-p/713787#M220266</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-01-25T00:08:01Z</dc:date>
    </item>
  </channel>
</rss>

