<?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: DO UNTIL WITHIN A BY GROUP in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61892#M17560</link>
    <description>In the DATA step, use an OUTPUT statement, making it's execution conditional on your required IF/THEN condition, such as:&lt;BR /&gt;
&lt;BR /&gt;
IF A LT TOT_A THEN OUTPUT;</description>
    <pubDate>Wed, 24 Feb 2010 22:14:37 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-02-24T22:14:37Z</dc:date>
    <item>
      <title>DO UNTIL WITHIN A BY GROUP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61891#M17559</link>
      <description>Please help...I am trying to run a loop and output all records within the by group until the runbal is less than or equal to 0.  Obs in bold is what I want to output.&lt;BR /&gt;
&lt;BR /&gt;
Here is the abbreviated dataset:&lt;BR /&gt;
custid$    oblgid$      runbal&lt;BR /&gt;
&lt;B&gt;1234         A             1536&lt;BR /&gt;
1234         A              0&lt;/B&gt;&lt;BR /&gt;
1234         A            1536  (do not want this one to output)&lt;BR /&gt;
&lt;B&gt;1235         A             0&lt;BR /&gt;
1236         A            500&lt;BR /&gt;
1236         A            0&lt;/B&gt;&lt;BR /&gt;
1236         A             -500    (do not want this one to output)                 &lt;BR /&gt;
&lt;BR /&gt;
Here is what I have so far, but can't seem to think of a way to get the right output.  If I do a DO UNTIL 0 then it only outputs one row.&lt;BR /&gt;
&lt;BR /&gt;
DATA MAXOBS_GT2_PAYDOWN;&lt;BR /&gt;
&lt;BR /&gt;
	SET MAXOBS_GT2;&lt;BR /&gt;
BY CUSTID OBLGID;&lt;BR /&gt;
RETAIN RUNBAL;&lt;BR /&gt;
IF FIRST.OBLGID THEN DO;&lt;BR /&gt;
RUNBALTEMP=CURRBALAMT;&lt;BR /&gt;
RUNBAL=RUNBALTEMP;&lt;BR /&gt;
END;&lt;BR /&gt;
RUNBALTEMP=RUNBAL;&lt;BR /&gt;
RUNBAL=RUNBALTEMP-PAID;&lt;BR /&gt;
&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Any help would be greatly appreciated.</description>
      <pubDate>Wed, 24 Feb 2010 22:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61891#M17559</guid>
      <dc:creator>redfishJAX</dc:creator>
      <dc:date>2010-02-24T22:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL WITHIN A BY GROUP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61892#M17560</link>
      <description>In the DATA step, use an OUTPUT statement, making it's execution conditional on your required IF/THEN condition, such as:&lt;BR /&gt;
&lt;BR /&gt;
IF A LT TOT_A THEN OUTPUT;</description>
      <pubDate>Wed, 24 Feb 2010 22:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61892#M17560</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-24T22:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL WITHIN A BY GROUP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61893#M17561</link>
      <description>Thanks...&lt;BR /&gt;
&lt;BR /&gt;
But I am not sure it will work since I don't always want to output if the condition is true.  I want to output the obs until the value gets to zero (also output the zero value as well). The following obs after the value is zero, I want to exclude.</description>
      <pubDate>Thu, 25 Feb 2010 13:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61893#M17561</guid>
      <dc:creator>redfishJAX</dc:creator>
      <dc:date>2010-02-25T13:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL WITHIN A BY GROUP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61894#M17562</link>
      <description>Suggest you try some IF / THEN coding in your DATA step - add self-checking diagnostic statement such as:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG '&amp;gt;DIAG&amp;gt; I am here.' / _ALL_;&lt;BR /&gt;
&lt;BR /&gt;
With this additional log output, you will see each SAS variable value as your DATA step iterates -- you may need to put in multiple PUTLOG statements to experiment with your program.&lt;BR /&gt;
&lt;BR /&gt;
I suspect that you can address your "conditional output" scenario with some statement in the form:&lt;BR /&gt;
&lt;BR /&gt;
IF (&lt;SOME expression=""&gt;) THEN OUTPUT;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
and you may need to keep a running SAS temporary numeric variable, either using possibly some combination of accumulation with a RETAIN and then DROP the temp variable.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/SOME&gt;</description>
      <pubDate>Thu, 25 Feb 2010 13:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DO-UNTIL-WITHIN-A-BY-GROUP/m-p/61894#M17562</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-02-25T13:44:21Z</dc:date>
    </item>
  </channel>
</rss>

