<?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: Counting Using a DO UNTIL Loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804155#M33404</link>
    <description>&lt;P&gt;Thank you so much! It worked exactly how I needed it to.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 18:07:52 GMT</pubDate>
    <dc:creator>ssills24</dc:creator>
    <dc:date>2022-03-25T18:07:52Z</dc:date>
    <item>
      <title>Counting Using a DO UNTIL Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804144#M33400</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to count a variable up until a certain point. I have attached the code I have been trying to use below and have attached the table I have gotten thus far. Whenever I run this code, it will continue running and creating way more observations that I have.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA DisProj.Count;&lt;BR /&gt;SET WORK.Loop;&lt;BR /&gt;BY Person;&lt;/P&gt;&lt;P&gt;LENGTH count 8;&lt;/P&gt;&lt;P&gt;RETAIN count;&lt;/P&gt;&lt;P&gt;DO UNTIL (Outpatient_MOUD = 1);&lt;/P&gt;&lt;P&gt;IF FIRST.Person THEN count = 1;&lt;BR /&gt;ELSE count = count+1;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I would like to count the outpatient_MOUD variable UNTIL it reaches zero, and then stop counting. I only want the sum up to the first zero.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated! Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 17:14:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804144#M33400</guid>
      <dc:creator>ssills24</dc:creator>
      <dc:date>2022-03-25T17:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Using a DO UNTIL Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804145#M33401</link>
      <description>&lt;P&gt;There is nothing in your DO loop that could possible change the value of that variable.&lt;/P&gt;
&lt;P&gt;What is it you want to count?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want to count the number of people until you find the first one that is an outpatient?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data count;
  set have;
  by person;
  count+first.person;
  if outpatient=1 then do;
     output;
    put _n_= count= ;
     stop;
  end;
  keep count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 17:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804145#M33401</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-25T17:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Using a DO UNTIL Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804148#M33402</link>
      <description>Hi Tom,&lt;BR /&gt;&lt;BR /&gt;I am trying to count how many "1"s each person has. For example, person 1 has 26 because they have no 0s. Person 2 has only 20, 1s before a zero is encountered. I am trying to count the number of "1"s before a zero is encountered for each person.&lt;BR /&gt;&lt;BR /&gt;Thank You.</description>
      <pubDate>Fri, 25 Mar 2022 17:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804148#M33402</guid>
      <dc:creator>ssills24</dc:creator>
      <dc:date>2022-03-25T17:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Using a DO UNTIL Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804153#M33403</link>
      <description>&lt;P&gt;Your DATA step keeps on processing the same observation over and over again.&amp;nbsp; To break out of that, try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA DisProj.Count;
SET WORK.No_Loop_needed;
BY Person;
retain increment;
if first.person then do;
   increment = Outpatient_MOUD;
   count = 0;
end;
else if Outpatient_MOUD = 0 then increment = 0;
count + increment;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Optionally, to get just the final count per person, add this statement before the RUN statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.person;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 18:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804153#M33403</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-25T18:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Using a DO UNTIL Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804155#M33404</link>
      <description>&lt;P&gt;Thank you so much! It worked exactly how I needed it to.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 18:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804155#M33404</guid>
      <dc:creator>ssills24</dc:creator>
      <dc:date>2022-03-25T18:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Using a DO UNTIL Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804160#M33405</link>
      <description>&lt;P&gt;You should remove the ELSE so it counts properly when the first value is zero.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 18:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-Using-a-DO-UNTIL-Loop/m-p/804160#M33405</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-25T18:30:43Z</dc:date>
    </item>
  </channel>
</rss>

