<?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: loop in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857148#M338658</link>
    <description>&lt;P&gt;Use a macro loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%do i = 1 %to 100;
create table new&amp;amp;i as
  select distinct a.*,b.date, b.date2, b.x, b.y, b.z 
  from v&amp;amp;i a, &amp;amp;data b
  where abs(a.date-b.date)&amp;lt;=29
  group by a.id, a.date
  having abs(a.date2-b.date2) eq min(abs(a.date2-b.date2))
;
%end;
%mend;
proc sql;
%loop
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What keeps you from combining the 100 datasets into one in the first place?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since dates are counts of days, you don't need the INTCK function. A simple subtraction will be faster.&lt;/P&gt;</description>
    <pubDate>Sat, 04 Feb 2023 08:32:23 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-04T08:32:23Z</dc:date>
    <item>
      <title>loop in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857147#M338657</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to run a proc sql for 100 datasets and was wondering if it is possible to use a do loop instead of writing the same code 100 times. here is my proc sql:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
  create table new&amp;amp;i as
    select distinct a.*,b.date, b.date2, b.x, b.y, b.z 
      from v&amp;amp;i a, &amp;amp;data b
      where abs(intck('day',a.date,b.date))&amp;lt;=29
      group by a.id, a.date
        having abs(a.date2-b.date2) eq min(abs(a.date2-b.date2))
  ;
quit;&lt;/PRE&gt;&lt;P&gt;Any help is greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 08:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857147#M338657</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2023-02-04T08:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: loop in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857148#M338658</link>
      <description>&lt;P&gt;Use a macro loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop;
%do i = 1 %to 100;
create table new&amp;amp;i as
  select distinct a.*,b.date, b.date2, b.x, b.y, b.z 
  from v&amp;amp;i a, &amp;amp;data b
  where abs(a.date-b.date)&amp;lt;=29
  group by a.id, a.date
  having abs(a.date2-b.date2) eq min(abs(a.date2-b.date2))
;
%end;
%mend;
proc sql;
%loop
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What keeps you from combining the 100 datasets into one in the first place?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since dates are counts of days, you don't need the INTCK function. A simple subtraction will be faster.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 08:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857148#M338658</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-04T08:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: loop in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857181#M338681</link>
      <description>Thank you for the code! The dataset is huge and takes forever to run this code. so I split it into 100 smaller datasets.</description>
      <pubDate>Sat, 04 Feb 2023 16:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-in-proc-sql/m-p/857181#M338681</guid>
      <dc:creator>AmirSari</dc:creator>
      <dc:date>2023-02-04T16:09:24Z</dc:date>
    </item>
  </channel>
</rss>

