<?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 Using i counter of loop in keep statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152085#M29952</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I would like just as many array variables in the ouput dataset as there are loops. If the loop only runs three times and creates x1, x2, and x3, I would like to just keep those three variables and not all five. Using a macro that is being created within the same data step does not work and I'm pretty sure I know why. Any suggestions? Thanks! data dummy;&amp;nbsp;&amp;nbsp; checker=3;&amp;nbsp;&amp;nbsp; array x[5] $100.;&amp;nbsp;&amp;nbsp; do i = 1 to 10 while (checker &amp;gt; 0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x&lt;I&gt; = 1 + 2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checker = checker - 1;&amp;nbsp;&amp;nbsp; end;&amp;nbsp;&amp;nbsp; call symputx("i",i);&amp;nbsp;&amp;nbsp; keep x1 - x&amp;amp;i; run; Not sure if this code actually runs. I just recreated something similar to my problem. Regards Phil&lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Aug 2014 17:49:14 GMT</pubDate>
    <dc:creator>PhilfromGermany</dc:creator>
    <dc:date>2014-08-06T17:49:14Z</dc:date>
    <item>
      <title>Using i counter of loop in keep statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152085#M29952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, I would like just as many array variables in the ouput dataset as there are loops. If the loop only runs three times and creates x1, x2, and x3, I would like to just keep those three variables and not all five. Using a macro that is being created within the same data step does not work and I'm pretty sure I know why. Any suggestions? Thanks! data dummy;&amp;nbsp;&amp;nbsp; checker=3;&amp;nbsp;&amp;nbsp; array x[5] $100.;&amp;nbsp;&amp;nbsp; do i = 1 to 10 while (checker &amp;gt; 0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x&lt;I&gt; = 1 + 2;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; checker = checker - 1;&amp;nbsp;&amp;nbsp; end;&amp;nbsp;&amp;nbsp; call symputx("i",i);&amp;nbsp;&amp;nbsp; keep x1 - x&amp;amp;i; run; Not sure if this code actually runs. I just recreated something similar to my problem. Regards Phil&lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 17:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152085#M29952</guid>
      <dc:creator>PhilfromGermany</dc:creator>
      <dc:date>2014-08-06T17:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using i counter of loop in keep statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152086#M29953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Phil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This can't be done in a single step.&amp;nbsp; The DATA step must be 100% compiled, including resolution of all macro variables referenced, before it executes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is easily possible to do this in two steps.&amp;nbsp; You could easily add a second DATA step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dummy;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set dummy (keep=x1-x&amp;amp;i);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That means reading/writing the observations again of course.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Aug 2014 18:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152086#M29953</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-08-06T18:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using i counter of loop in keep statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152087#M29954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your response, Astounding. My goal was to do it all in one data step, but after all this is an easy solution and it works. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 07:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152087#M29954</guid>
      <dc:creator>PhilfromGermany</dc:creator>
      <dc:date>2014-08-07T07:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using i counter of loop in keep statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152088#M29955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of a second datastep why not place the keep data set options in the first one: data dummy (keep=x1-x&amp;amp;i .....) ; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 07:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152088#M29955</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-07T07:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using i counter of loop in keep statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152089#M29956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wouldn't that cause the same problem, since the data step needs to compile completely before the macro can be referenced?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 07:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152089#M29956</guid>
      <dc:creator>PhilfromGermany</dc:creator>
      <dc:date>2014-08-07T07:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using i counter of loop in keep statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152090#M29957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are right, did not notice the logic in your example.&lt;/P&gt;&lt;P&gt;Often I see this with a the datastep being included knowing the counter already. I did my&amp;nbsp; conclusion too fast.&amp;nbsp; &lt;/P&gt;&lt;P&gt;I did not get your logic as you did not mentioning that with your question. It seem not to be on dataprocessing it is possible matrices. &lt;/P&gt;&lt;P&gt;Often that is more easier to solve in an other way. We are all often mindblocked by some previous successes&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Aug 2014 08:17:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-i-counter-of-loop-in-keep-statement/m-p/152090#M29957</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-07T08:17:29Z</dc:date>
    </item>
  </channel>
</rss>

