<?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 how to do an iterative loop in proc sql; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460332#M116995</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm trying to write a simple do loop where it'll iterate over a table a few times and create a new table. My logic is as follows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let K=1 to 2 by .25;
Proc sql;
Create table as TableAt_K
SELECT
Column,
Column2*k
from Table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want my code to run from 1 to 2, and each time, it'll multiply column*k and create&amp;nbsp;a new table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 May 2018 22:59:26 GMT</pubDate>
    <dc:creator>mrdlau</dc:creator>
    <dc:date>2018-05-06T22:59:26Z</dc:date>
    <item>
      <title>how to do an iterative loop in proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460332#M116995</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I'm trying to write a simple do loop where it'll iterate over a table a few times and create a new table. My logic is as follows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let K=1 to 2 by .25;
Proc sql;
Create table as TableAt_K
SELECT
Column,
Column2*k
from Table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want my code to run from 1 to 2, and each time, it'll multiply column*k and create&amp;nbsp;a new table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 May 2018 22:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460332#M116995</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-05-06T22:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to do an iterative loop in proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460333#M116996</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro iterate;

%do K=1 %to 2 %by .25;
Proc sql;
Create table as TableAt_&amp;amp;K
SELECT
Column,
Column2*&amp;amp;k
from Table1;
quit;

%end;

%mend;

%iterate&lt;BR /&gt;&lt;BR /&gt;/*or*/&lt;BR /&gt;&lt;BR /&gt;%macro iterate;&lt;BR /&gt;Proc sql;&lt;BR /&gt;%do K=1 %to 2 %by .25;&lt;BR /&gt;Create table as TableAt_&amp;amp;K&lt;BR /&gt;SELECT&lt;BR /&gt;Column,&lt;BR /&gt;Column2*&amp;amp;k&lt;BR /&gt;from Table1;&lt;BR /&gt;%end;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%iterate&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 May 2018 23:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460333#M116996</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-06T23:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to do an iterative loop in proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460338#M116999</link>
      <description>&lt;P&gt;I don't think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s code will work, but the following should:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
  input column column2;
  cards;
5 10
6 12
5 2
;

%macro iterate;

  %do K=100 %to 200 %BY 25;
    %let L=%sysfunc(catt(%sysfunc(int(%eval(&amp;amp;k./100))),dot,
      %eval(&amp;amp;k.-%sysfunc(int(%eval(&amp;amp;k./100)*100)))));
    Proc sql;
      Create table TableAt_&amp;amp;L. as 
        SELECT
              Column,
              Column2*&amp;amp;k
          from Table1
     ;
    quit;

  %end;

%mend;

%iterate&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 00:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460338#M116999</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-07T00:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to do an iterative loop in proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460619#M117098</link>
      <description>&lt;P&gt;thank you so much!&amp;nbsp; I ran this in SAS studio and it gave me what I needed.&amp;nbsp; Can you clarify what these syntax&amp;nbsp;are doing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    %let L=%sysfunc(catt(%sysfunc(int(%eval(&amp;amp;k./100))),dot,
      %eval(&amp;amp;k.-%sysfunc(int(%eval(&amp;amp;k./100)*100)))));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;there seems to be a lot going and I dont understand the negative sign, division etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, why are my tabe name "1dot0" "1dot25" etc?&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 03:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460619#M117098</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-05-08T03:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to do an iterative loop in proc sql;</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460620#M117099</link>
      <description>&lt;P&gt;The %let statement is simply doing what you originally asked for. Since macro do loops can't handle fractions, I used 100 to 200 by 25, rather than 1 to 2 by .25. Also, since SAS dataset names can only contain alpha, numeric and underscore characters, rather than try to create an illegal name&amp;nbsp;that contained a ., I created names like table1dot0 rather than table1.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %let statement simply built the 1dot0, 1dot25, etc. parts of the name. The first part would take a number like 125 and reduce it to 1, the the characters 'dot' were added, followed by the fraction (e.g., 125-100=25).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 03:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-an-iterative-loop-in-proc-sql/m-p/460620#M117099</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-08T03:57:16Z</dc:date>
    </item>
  </channel>
</rss>

