<?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: Macro running on month condition in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556449#M74753</link>
    <description>&lt;P&gt;TODAY() returns todays date&lt;/P&gt;
&lt;P&gt;MONTH() retrieves the month from a SAS date.&lt;/P&gt;
&lt;P&gt;To use functions within macro logic, wrap them in %SYSFUNC().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not really sure where the other month value is coming from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(today(), month.) = 5 %then %do;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259057"&gt;@sasnewbiexx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I'm trying to create the following macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;%Macro CheckDate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &lt;EM&gt;&lt;FONT color="#808080"&gt;&amp;amp;month&lt;/FONT&gt;&lt;/EM&gt;= &lt;FONT color="#808080"&gt;&lt;EM&gt;&lt;U&gt;this month&lt;/U&gt;&lt;/EM&gt;&lt;/FONT&gt; %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Proc Sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Create table Work.Test1 as&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Select A.*&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; From Work.Table1&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Quit;&lt;/P&gt;
&lt;P&gt;%End;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Else %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;signoff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%End;&lt;BR /&gt;%Mend;&lt;BR /&gt;%CheckDate;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get my &lt;EM&gt;&lt;FONT color="#808080"&gt;month&amp;nbsp;&lt;/FONT&gt;&lt;/EM&gt;macrovariable&amp;nbsp;to be the month part for the first observation from a datetime column from another table (lets say Work.Table2). Any ideas how can I do that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2019 14:55:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-05-06T14:55:24Z</dc:date>
    <item>
      <title>Macro running on month condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556432#M74751</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, I'm trying to create the following macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;%Macro CheckDate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &lt;EM&gt;&lt;FONT color="#808080"&gt;&amp;amp;month&lt;/FONT&gt;&lt;/EM&gt;= &lt;FONT color="#808080"&gt;&lt;EM&gt;&lt;U&gt;this month&lt;/U&gt;&lt;/EM&gt;&lt;/FONT&gt; %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Proc Sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Create table Work.Test1 as&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Select A.*&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; From Work.Table1&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Quit;&lt;/P&gt;&lt;P&gt;%End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;signoff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%End;&lt;BR /&gt;%Mend;&lt;BR /&gt;%CheckDate;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get my &lt;EM&gt;&lt;FONT color="#808080"&gt;month&amp;nbsp;&lt;/FONT&gt;&lt;/EM&gt;macrovariable&amp;nbsp;to be the month part for the first observation from a datetime column from another table (lets say Work.Table2). Any ideas how can I do that?&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 14:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556432#M74751</guid>
      <dc:creator>sasnewbiexx</dc:creator>
      <dc:date>2019-05-06T14:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro running on month condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556442#M74752</link>
      <description>&lt;P&gt;Here's the sort of information you will need to supply to approach this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is in that datetime value from the other table?&amp;nbsp; Is it a character string?&amp;nbsp; Is it a SAS numeric datetime?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you intend to populate "this month"?&amp;nbsp; Is it something you feed in as a parameter?&amp;nbsp; (If so, is it a number from 1 to 12, or a three-letter abbreviation, or a full word?)&amp;nbsp; Is it the month during which the program runs?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it always sufficient to check just the month, so you will never need to check the year as well?&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>Mon, 06 May 2019 14:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556442#M74752</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-06T14:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro running on month condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556449#M74753</link>
      <description>&lt;P&gt;TODAY() returns todays date&lt;/P&gt;
&lt;P&gt;MONTH() retrieves the month from a SAS date.&lt;/P&gt;
&lt;P&gt;To use functions within macro logic, wrap them in %SYSFUNC().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not really sure where the other month value is coming from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %sysfunc(today(), month.) = 5 %then %do;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/259057"&gt;@sasnewbiexx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I'm trying to create the following macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;%Macro CheckDate;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if &lt;EM&gt;&lt;FONT color="#808080"&gt;&amp;amp;month&lt;/FONT&gt;&lt;/EM&gt;= &lt;FONT color="#808080"&gt;&lt;EM&gt;&lt;U&gt;this month&lt;/U&gt;&lt;/EM&gt;&lt;/FONT&gt; %then %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Proc Sql;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Create table Work.Test1 as&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Select A.*&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; From Work.Table1&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Quit;&lt;/P&gt;
&lt;P&gt;%End;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%Else %do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;signoff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%End;&lt;BR /&gt;%Mend;&lt;BR /&gt;%CheckDate;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to get my &lt;EM&gt;&lt;FONT color="#808080"&gt;month&amp;nbsp;&lt;/FONT&gt;&lt;/EM&gt;macrovariable&amp;nbsp;to be the month part for the first observation from a datetime column from another table (lets say Work.Table2). Any ideas how can I do that?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 14:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556449#M74753</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-06T14:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro running on month condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556680#M74764</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The datetime format from the other table is DATETIME22.3 (&lt;EM&gt;11APR2019:10:27:15.780&lt;/EM&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologizes, when I say "this month", I meant to say the current month's value. I intend to take from SAS, but I'm not sure how in this case given the format of the date value from the other table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table that I take the date from gets updated once a month, but the DBA told me that it is not on a prefixed date so it can be in the beginning of the month or the end. Therefore, my idea is to make my program execute only if the month value is different than the current month's value and just skip to signoff if the month values match.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wouldn't need to check the year since the data is updated every month and all the values in the datetime column I take are from the same day.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 07:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556680#M74764</guid>
      <dc:creator>sasnewbiexx</dc:creator>
      <dc:date>2019-05-07T07:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro running on month condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556769#M74766</link>
      <description>&lt;P&gt;Since you need to pull data from a separate data set to get the comparison datetime value, I would recommend using a DATA step and doing all the heavy lifting in that DATA step.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro CheckDate;
   
   %local proceed;
   %let proceed=N;
   data _null_;
      set other_table (keep=last_update_datetime);
      if month(today()) ne month(datepart(last_update_datetime)) then
      call symput('proceed', 'Y');
      stop;
   run;
   %if &amp;amp;proceed=Y %then %do;
      ...
   %end;
    %else %do;
         * signoff logic;
    %end;

%mend CheckDate;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, I had to invent names for your data sets and variables.&amp;nbsp; And I assumed that your datetime source is actually a numeric SAS datetime, not a character string.&amp;nbsp; All of that can be tweaked if necessary.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 13:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/556769#M74766</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-07T13:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro running on month condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/557114#M74773</link>
      <description>Thank you so much, this was exactly what I was looking for! Cheers!</description>
      <pubDate>Wed, 08 May 2019 14:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-running-on-month-condition/m-p/557114#M74773</guid>
      <dc:creator>sasnewbiexx</dc:creator>
      <dc:date>2019-05-08T14:01:46Z</dc:date>
    </item>
  </channel>
</rss>

