<?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: How to reduce time taken by sas macro code to run in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/813164#M320878</link>
    <description>&lt;P&gt;Just by "pruning" the code to the bits that might actually do something it looks to me that if macro call&amp;nbsp;&lt;CODE class=" language-sas"&gt;%vbt_status_rpt;&lt;/CODE&gt;&amp;nbsp;doesn't set&amp;nbsp;&lt;CODE class=" language-sas"&gt;&amp;amp;flag=y&lt;/CODE&gt;&amp;nbsp; then you've coded yourself an infinite loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO monthly_schedule;
  %let flag=n;

  %do %until(&amp;amp;flag=y);

    proc sql noprint;
      select count(update_flag) into:flag_cnt
        from work.schedule_dt
          where update_flag = 1 and Business in ('Spain' 'England')
      ;
    quit;

    %PUT &amp;amp;flag_cnt.;

    %if &amp;amp;end_date. &amp;gt; &amp;amp;lastest_refrsh_dt. %then
      %do;
        /*Execute vbt status rpt and email to recipients */
        %if %eval(&amp;amp;flag_cnt)=9 %then
          %do;
            %let flag_cnt=Y;
            %put The flags are updated.;

            %vbt_status_rpt;
            %send_vbt_email;

            /*update Config table*/
            proc sql noprint;
              delete from config table where location ='abc' AND SUB ='cde' and value ='31-Mar-22'd;
            quit;

            proc sql noprint;
              INSERT INTO config table (Location, SUB, Value)
                VALUES ( "abc", "cde", '30-Apr-22'd);
            quit;

          %end;
      %end;
  %end;
%else
  %do;
    %put The flags are not updated;
  %end;
%end;
%mend monthly_schedule;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As an impression of what you've shared: Your code needs some "cleaning-up". Try to write macros that are modules on it's own and also try to not have hardcoded values within the macro that require regular change (like the hardcoded dates).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below bit is certainly not good macro design/coding practice&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1652437494302.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71414i9C52BF51E4894612/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1652437494302.png" alt="Patrick_0-1652437494302.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2022 10:25:10 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-05-13T10:25:10Z</dc:date>
    <item>
      <title>How to reduce time taken by sas macro code to run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/812931#M320761</link>
      <description>&lt;P&gt;I need help with my monthly report sas code below:&lt;BR /&gt;Firstly the code takes too long to run while the data is relatively small. When it completes a message that reads: The contents of log is too large.&lt;/P&gt;&lt;P&gt;Please can you check what the issue which my code?&lt;/P&gt;&lt;P&gt;%MACRO monthly_schedule;&lt;BR /&gt;%let flag=n;&lt;BR /&gt;%do %until(&amp;amp;flag=y);&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select count(update_flag) into:flag_cnt&lt;BR /&gt;from work.schedule_dt&lt;BR /&gt;where update_flag = 1 and Business in ('Spain' 'England')&lt;BR /&gt;; quit;&lt;/P&gt;&lt;P&gt;%PUT &amp;amp;flag_cnt.;&lt;/P&gt;&lt;P&gt;%if &amp;amp;end_date. &amp;gt; &amp;amp;lastest_refrsh_dt. %then&lt;BR /&gt;%do;&lt;BR /&gt;/*Execute vbt status rpt and email to recipients */&lt;BR /&gt;%if %eval(&amp;amp;flag_cnt)=9 %then&lt;BR /&gt;%do;&lt;BR /&gt;%let flag_cnt=Y;&lt;BR /&gt;%put The flags are updated.;&lt;/P&gt;&lt;P&gt;%vbt_status_rpt;&lt;BR /&gt;%send_vbt_email;&lt;/P&gt;&lt;P&gt;/*update Config table*/&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;delete from config table where location ='abc' AND SUB ='cde' and value ='31-Mar-22'd;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;INSERT INTO config table (Location, SUB, Value)&lt;BR /&gt;VALUES ( "abc", "cde", '30-Apr-22'd);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend vbt_monthly_schedule;&lt;/P&gt;&lt;P&gt;%vbt_monthly_schedule;&lt;BR /&gt;%else&lt;BR /&gt;%do;&lt;BR /&gt;%put The flags are not updated;&lt;BR /&gt;/* Send email if data is not available after the 6th Day */&lt;BR /&gt;%macro send_sixthdy_email;&lt;BR /&gt;%let today = %sysfunc(today() );&lt;BR /&gt;%if( %sysfunc(intnx(month, &amp;amp;today., 0, B) ) NE &amp;amp;lastest_refrsh_dt.&lt;BR /&gt;AND %sysfunc(day(&amp;amp;today.) ) GE 3&lt;BR /&gt;AND 2 LE %sysfunc(weekday(&amp;amp;today.) ) LE 3&lt;BR /&gt;) %then&lt;BR /&gt;%do;&lt;BR /&gt;%put lastest_refrsh_dt is &amp;amp;lastest_refrsh_dt.;&lt;BR /&gt;/* send email if data not ready by the 6th */&lt;BR /&gt;%emailnotification(ctnt=%str(data not available),&lt;BR /&gt;subj=%str(data not available ),&lt;BR /&gt;mailist ="j@yah");&lt;BR /&gt;%end;&lt;BR /&gt;%mend send_sixthdy_email;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend monthly_schedule;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 12:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/812931#M320761</guid>
      <dc:creator>tnachis</dc:creator>
      <dc:date>2022-05-12T12:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce time taken by sas macro code to run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/812937#M320765</link>
      <description>&lt;P&gt;This is difficult to answer for a number of reasons.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;We don't have your data&lt;/LI&gt;
&lt;LI&gt;You are doing some looping which can be a problem, hard to say, we don't know what the looping is doing or how many iterations it will take&lt;/LI&gt;
&lt;LI&gt;You are using macros that we don't have&lt;/LI&gt;
&lt;LI&gt;Your code is not properly indented, it's difficult for humans to look at&lt;/LI&gt;
&lt;LI&gt;You have a macro definition containing and inside a loop is another macro definition, usually this is to be avoided and can cause the program to take a long time (and you never all this second macro anyway)&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Can you look at the log and see where the time delay is happening?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you place %PUT statements in the code to print out the current date/time so that you can identify where things are taking a long time?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 12:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/812937#M320765</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-12T12:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce time taken by sas macro code to run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/813164#M320878</link>
      <description>&lt;P&gt;Just by "pruning" the code to the bits that might actually do something it looks to me that if macro call&amp;nbsp;&lt;CODE class=" language-sas"&gt;%vbt_status_rpt;&lt;/CODE&gt;&amp;nbsp;doesn't set&amp;nbsp;&lt;CODE class=" language-sas"&gt;&amp;amp;flag=y&lt;/CODE&gt;&amp;nbsp; then you've coded yourself an infinite loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO monthly_schedule;
  %let flag=n;

  %do %until(&amp;amp;flag=y);

    proc sql noprint;
      select count(update_flag) into:flag_cnt
        from work.schedule_dt
          where update_flag = 1 and Business in ('Spain' 'England')
      ;
    quit;

    %PUT &amp;amp;flag_cnt.;

    %if &amp;amp;end_date. &amp;gt; &amp;amp;lastest_refrsh_dt. %then
      %do;
        /*Execute vbt status rpt and email to recipients */
        %if %eval(&amp;amp;flag_cnt)=9 %then
          %do;
            %let flag_cnt=Y;
            %put The flags are updated.;

            %vbt_status_rpt;
            %send_vbt_email;

            /*update Config table*/
            proc sql noprint;
              delete from config table where location ='abc' AND SUB ='cde' and value ='31-Mar-22'd;
            quit;

            proc sql noprint;
              INSERT INTO config table (Location, SUB, Value)
                VALUES ( "abc", "cde", '30-Apr-22'd);
            quit;

          %end;
      %end;
  %end;
%else
  %do;
    %put The flags are not updated;
  %end;
%end;
%mend monthly_schedule;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As an impression of what you've shared: Your code needs some "cleaning-up". Try to write macros that are modules on it's own and also try to not have hardcoded values within the macro that require regular change (like the hardcoded dates).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below bit is certainly not good macro design/coding practice&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1652437494302.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71414i9C52BF51E4894612/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1652437494302.png" alt="Patrick_0-1652437494302.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 10:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/813164#M320878</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-05-13T10:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce time taken by sas macro code to run</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/813178#M320882</link>
      <description>&lt;P&gt;Maxim 2: Read the Log. It will alert you to several serious issues.&lt;/P&gt;
&lt;P&gt;The first I see is that this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mend vbt_monthly_schedule;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;has no corresponding %MACRO statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some rules:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;NEVER&lt;/STRONG&gt; &lt;EM&gt;define&lt;/EM&gt; macros within other macros, only &lt;EM&gt;use&lt;/EM&gt; them&lt;/LI&gt;
&lt;LI&gt;Use indentation so your %DO - %END and DO - END blocks become visible&lt;/LI&gt;
&lt;LI&gt;when you have longer nested blocks, it is a good idea to add a comment to the END which describes to which DO it belongs&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;See this changed and annotated code that points out issues:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro send_sixthdy_email;
%let today = %sysfunc(today() );
%if( %sysfunc(intnx(month, &amp;amp;today., 0, B) ) NE &amp;amp;lastest_refrsh_dt.
AND %sysfunc(day(&amp;amp;today.) ) GE 3
AND 2 LE %sysfunc(weekday(&amp;amp;today.) ) LE 3
) %then
%do;
%put lastest_refrsh_dt is &amp;amp;lastest_refrsh_dt.;
/* send email if data not ready by the 6th */
%emailnotification(ctnt=%str(data not available),
subj=%str(data not available ),
mailist ="j@yah");
%end;
%mend send_sixthdy_email;

%MACRO monthly_schedule;

%let flag=n;
%do %until(&amp;amp;flag=y);

  proc sql noprint;
  select count(update_flag) into:flag_cnt
  from work.schedule_dt
  where update_flag = 1 and Business in ('Spain' 'England')
  ;
  quit;

  %PUT &amp;amp;flag_cnt.;
  %if &amp;amp;end_date. &amp;gt; &amp;amp;lastest_refrsh_dt.
  %then %do;
    /* Execute vbt status rpt and email to recipients */
    %if %eval(&amp;amp;flag_cnt)=9
    %then %do;
      %let flag_cnt=Y;
      %put The flags are updated.;

      %vbt_status_rpt;
      %send_vbt_email;

      /*update Config table*/
      proc sql noprint;
      delete from config table where location ='abc' AND SUB ='cde' and value ='31-Mar-22'd;
      quit;

      proc sql noprint;
      INSERT INTO config table (Location, SUB, Value)
      VALUES ( "abc", "cde", '30-Apr-22'd);
      quit;

    %end; /* if %eval(&amp;amp;flag_cnt)=9 */
  %end; /* if &amp;amp;end_date. &amp;gt; &amp;amp;lastest_refrsh_dt. */
%end; /* %do %until(&amp;amp;flag=y); */
%mend vbt_monthly_schedule; /* ERROR !!! */
%vbt_monthly_schedule;
%else %do;
  %put The flags are not updated;
  /* Send email if data is not available after the 6th Day */
  /* there is no code to do anything here !!! */
%end;
%end; /* one %END too much !!! */
%mend monthly_schedule;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It seems that you tried to do too much in one effort. Build your macro(s) small step by small step.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 11:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-time-taken-by-sas-macro-code-to-run/m-p/813178#M320882</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-13T11:35:48Z</dc:date>
    </item>
  </channel>
</rss>

