<?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: While Loop in proc sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/While-Loop-in-proc-sql/m-p/447717#M69552</link>
    <description>&lt;P&gt;Write the SQL for this part:&lt;/P&gt;
&lt;PRE&gt;Insert into some_sas_table
Select * from another table where Metrics_desc =&amp;amp;met_nm&lt;/PRE&gt;
&lt;P&gt;Once you get it to run for one metrics_desc, replace the value with a macro variable (&amp;amp;met_nm), and wrap it into a macro definition with met_nm as parameter.&lt;/P&gt;
&lt;P&gt;Then run that off your met_table with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set met_table;
call execute('%yourmac(' !! trim(metrics_desc) !! ');');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Mar 2018 10:33:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-22T10:33:52Z</dc:date>
    <item>
      <title>While Loop in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/While-Loop-in-proc-sql/m-p/447708#M69551</link>
      <description>&lt;P&gt;I have metrics sas table like below&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;work.met_table
Metrics_Id   Metrics_desc
     1       Count_Column
     2       Sum_Column
     3       Eliminate_column&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I wanna do something like doing while loop in T-sql&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select count(*) :cnt_tbl from work.met_table

%let init_cnt = 1

while (&amp;amp;init_cnt = &amp;amp;cnt_tbl)
begin
   select Metrics_desc into :met_nm
   from work.met_table
   where metrics_id = 1

    Insert into some_sas_table
    Select * from another table where Metrics_desc =&amp;amp;met_nm
       /* Here I wanna loop all values in metrics table one by one */
end
%put &amp;amp;init_cnt = &amp;amp;int_cnt+1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How this can be done in proc sql? Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 10:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/While-Loop-in-proc-sql/m-p/447708#M69551</guid>
      <dc:creator>Pradeepbanu</dc:creator>
      <dc:date>2018-03-22T10:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: While Loop in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/While-Loop-in-proc-sql/m-p/447717#M69552</link>
      <description>&lt;P&gt;Write the SQL for this part:&lt;/P&gt;
&lt;PRE&gt;Insert into some_sas_table
Select * from another table where Metrics_desc =&amp;amp;met_nm&lt;/PRE&gt;
&lt;P&gt;Once you get it to run for one metrics_desc, replace the value with a macro variable (&amp;amp;met_nm), and wrap it into a macro definition with met_nm as parameter.&lt;/P&gt;
&lt;P&gt;Then run that off your met_table with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set met_table;
call execute('%yourmac(' !! trim(metrics_desc) !! ');');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 10:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/While-Loop-in-proc-sql/m-p/447717#M69552</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-22T10:33:52Z</dc:date>
    </item>
  </channel>
</rss>

