<?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 do loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821150#M34883</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I want to select when itemstatus_01 and itemstatus_02...itemstatus_48 are all&amp;nbsp; "O". The problem is number of itemstatus variable changes for each grade. For example for grade 5 itemstatus_45 variable is blank since grade 5 kids did not take itemstatus_45 however grade 6 kids took it. Any ideas?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 14:37:51 GMT</pubDate>
    <dc:creator>dustychair</dc:creator>
    <dc:date>2022-06-30T14:37:51Z</dc:date>
    <item>
      <title>do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821150#M34883</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I want to select when itemstatus_01 and itemstatus_02...itemstatus_48 are all&amp;nbsp; "O". The problem is number of itemstatus variable changes for each grade. For example for grade 5 itemstatus_45 variable is blank since grade 5 kids did not take itemstatus_45 however grade 6 kids took it. Any ideas?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 14:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821150#M34883</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-06-30T14:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821162#M34884</link>
      <description>&lt;P&gt;So when itemstatus_45 is blank, and the rest are 'O', do you want to select it or not?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 15:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821162#M34884</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-30T15:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821164#M34885</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Thank you for your respones.&lt;/P&gt;
&lt;P&gt;The data set is something like that:&lt;/P&gt;
&lt;P&gt;grade itemstatus_01 itemstatus_02 itemstatus_45&lt;/P&gt;
&lt;P&gt;5 O O&lt;/P&gt;
&lt;P&gt;5 O F&lt;/P&gt;
&lt;P&gt;6 F F O&lt;/P&gt;
&lt;P&gt;6 O O O&lt;/P&gt;
&lt;P&gt;6 F O O&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so I want to select when grade is 5 and all itemstatus variables are "O". For grade 5 it is up to itemstatus_44; for grade 6 it is 48. I am trying to write a loop but I could not.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 15:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821164#M34885</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-06-30T15:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821165#M34886</link>
      <description>&lt;P&gt;How many different rules for the number of "items" are to be processed?&lt;/P&gt;
&lt;P&gt;Are all of these "items" all always exactly one character long? I ask because the shortest code will work if "O" does not also appear in a composite form such as "OOP".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way that may get you started. Since you did not provide any example I made a small set with 5 variables to demonstrate ways to count &lt;STRONG&gt;if&lt;/STRONG&gt; the 'O' is not duplicated in any variable.&lt;/P&gt;
&lt;PRE&gt;data junk;
   informat i1 - i6 $1.;
   input i1 - i6;
   num_0 = countc(cats(of i:),'O');
   num_0_2= countc(cats(of i1-i3,i5),'O');
datalines;
O O O O O O
O A O A O A
;&lt;/PRE&gt;
&lt;P&gt;The above code uses the CATS function to combine the variables into a single string and then uses the CountC function to see how many times the 'O' appears which is why knowledge of actual codes used is important. If 'OP' is legal then the above does not work as it would count that as one of the 'O' values.&lt;/P&gt;
&lt;P&gt;The Cats function will allow use of variable lists when the key word "of" is used. The colon following part of variable name says "use all variable names that start with" up to the colon. You would use Itemstatus_: for that purpose. The second shows a limited sequential list "of i1-i3" uses i1,12 and 13. You can add other individual variables or other lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question about grade 5 vs 6 may not be important at the counting step as the Itemstatus_: list with the CATS function means that blanks get excluded. The question would be LATER when you are using that count with different grades.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 15:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821165#M34886</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-30T15:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821177#M34888</link>
      <description>&lt;P&gt;So for&amp;nbsp;grade 5 you want to detect 44 consecutive O's in itemstatus_01 through itemstatus_44.&lt;/P&gt;
&lt;P&gt;And for&amp;nbsp;grade 6 you want to detect 48 consecutive O's in itemstatus_01 through itemstatus_48.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can concatenate the values of itemstatus_01 through itemstatus_44 (or 48) and test against a constant string value of 44 (or 48) O's:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mysample (drop=_:);
  retain _qualify5 "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO";      **44 letter O's;
  retain _qualify6 "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO0000";  **48 letter O's;
  set have;
  if (grade=5 and cats(of itemstatus_01-itemstatus_44)=_qualify5)
  or (grade=6 and cats(of itemstatus_01-itemstatus_48)=_qualify6);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you're worried about typing exactly correct number of O's, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mysample (drop=_:);
  retain _qualify5   "%sysfunc(repeat(O,43))";   **44 letter O's;
  retain _qualify6   "%sysfunc(repeat(O,47))";   **48 letter O's;
  set have;
  if (grade=5 and cats(of itemstatus_01-itemstatus_44)=_qualify5)
  or (grade=6 and cats(of itemstatus_01-itemstatus_48)=_qualify6);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: to produce N x's, you have to use N-1 as the repetition count in the repeat function.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 16:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821177#M34888</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-06-30T16:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: do loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821178#M34889</link>
      <description>&lt;P&gt;Here's my attempt. I am using variables named Y1 Y2 etc instead of typing the much longer variable names you have. Flag=1 indicates a value that was not either 'O' or missing was found. Flag=0 indicates all variables have 'O' or missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array y y:;
    flag=0;
    do i=1 to dim(y);
        if y(i) not in ('O',' ') then do;
            flag=1;
            leave;
        end;
    end;
    drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2022 17:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/do-loop/m-p/821178#M34889</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-30T17:30:46Z</dc:date>
    </item>
  </channel>
</rss>

