<?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: Improve speed for this script in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893996#M353174</link>
    <description>&lt;P&gt;You could re-write your macro as below so it doesn't read the source table 101 times.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There would be other improvements possible but I've taken a "least change" approach to the code you've shared.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname txn "%sysfunc(pathname(work))";
data txn.append_txn;
  do report_date="31jan2014"d,"30jun2020"d;
    output;
  end;
run;

data _null_;
  format a date9.;
  do i=1 to 101;
    a=intnx('month',"31jan2014"d,i,'e');
    call symput(compress("dt"||i),a);
    call symput('cnt',i);
  end;
run;

%macro x();
  data
  %do i=1 %to &amp;amp;cnt;
    %let y=%sysfunc(putn(&amp;amp;&amp;amp;dt&amp;amp;i,date9.));
    a_&amp;amp;y
  %end;
  %str(;)
  set txn.append_txn;

  %do i=1 %to &amp;amp;cnt;
    %let y=%sysfunc(putn(&amp;amp;&amp;amp;dt&amp;amp;i,date9.));
    if report_date=&amp;amp;&amp;amp;dt&amp;amp;i then output a_&amp;amp;y;
    %if &amp;amp;i ne &amp;amp;cnt %then %str(else);
  %end;
  run;

%mend;

%x();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you really need to create these monthly tables then I'd suggest that you use a naming pattern &amp;lt;base_name&amp;gt;_&amp;lt;yyyymmdd&amp;gt; with the date being beginning of the month.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2023 06:29:59 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-09-13T06:29:59Z</dc:date>
    <item>
      <title>Improve speed for this script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893994#M353172</link>
      <description>&lt;P&gt;I have script as below but it is running pretty slow... any way to make it run faster?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;format a date9.;&lt;BR /&gt;do i=1 to 101;&lt;BR /&gt;a=intnx('month',"31jan2014"d,i,'e');&lt;BR /&gt;call symput(compress("dt"||i),a);&lt;BR /&gt;call symput('cnt',i);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%macro x;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;cnt;&lt;BR /&gt;%let y=%sysfunc(putn(&amp;amp;&amp;amp;dt&amp;amp;i,date9.));&lt;BR /&gt;data a_&amp;amp;y;&lt;BR /&gt;set txn.append_txn;&lt;/P&gt;&lt;P&gt;if report_date=&amp;amp;&amp;amp;dt&amp;amp;i then&lt;BR /&gt;output;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;BR /&gt;%x;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 05:40:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893994#M353172</guid>
      <dc:creator>TienHan83</dc:creator>
      <dc:date>2023-09-13T05:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Improve speed for this script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893996#M353174</link>
      <description>&lt;P&gt;You could re-write your macro as below so it doesn't read the source table 101 times.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There would be other improvements possible but I've taken a "least change" approach to the code you've shared.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname txn "%sysfunc(pathname(work))";
data txn.append_txn;
  do report_date="31jan2014"d,"30jun2020"d;
    output;
  end;
run;

data _null_;
  format a date9.;
  do i=1 to 101;
    a=intnx('month',"31jan2014"d,i,'e');
    call symput(compress("dt"||i),a);
    call symput('cnt',i);
  end;
run;

%macro x();
  data
  %do i=1 %to &amp;amp;cnt;
    %let y=%sysfunc(putn(&amp;amp;&amp;amp;dt&amp;amp;i,date9.));
    a_&amp;amp;y
  %end;
  %str(;)
  set txn.append_txn;

  %do i=1 %to &amp;amp;cnt;
    %let y=%sysfunc(putn(&amp;amp;&amp;amp;dt&amp;amp;i,date9.));
    if report_date=&amp;amp;&amp;amp;dt&amp;amp;i then output a_&amp;amp;y;
    %if &amp;amp;i ne &amp;amp;cnt %then %str(else);
  %end;
  run;

%mend;

%x();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you really need to create these monthly tables then I'd suggest that you use a naming pattern &amp;lt;base_name&amp;gt;_&amp;lt;yyyymmdd&amp;gt; with the date being beginning of the month.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 06:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893996#M353174</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-13T06:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Improve speed for this script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893997#M353175</link>
      <description>&lt;P&gt;Why do you think you need those 101 separate datasets?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 06:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/893997#M353175</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-13T06:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Improve speed for this script</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/894002#M353179</link>
      <description>&lt;P&gt;Do you want to limit the observations in append_txn to the results that lay in a 101 days time range?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startDate="31jan2014"d;
data want;
   set txn.append_txn;
   where &amp;amp;startDate.&amp;lt;=report_date&amp;lt;=intnx('day',&amp;amp;startDate.,101);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2023 07:33:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Improve-speed-for-this-script/m-p/894002#M353179</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-09-13T07:33:36Z</dc:date>
    </item>
  </channel>
</rss>

