<?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: creating conditions using date range and generating a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321496#M71010</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if "&amp;amp;sysdate"d &amp;gt;= "28feb2016"d and "&amp;amp;sysdate"d &amp;lt; "30jan2017"d
then call symput('cmt','*');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's much easier in a data step.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Dec 2016 22:52:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-12-28T22:52:50Z</dc:date>
    <item>
      <title>creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321492#M71008</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a macro variable conditional on a date range.&amp;nbsp;The&amp;nbsp;condition is if&amp;nbsp;todays date (according to my SAS machine) is&lt;/P&gt;&lt;P&gt;within a certain time period then I&amp;nbsp;would create the macro variable&amp;nbsp;CMT which resloves to a * .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have tried using the %if %then but was unsuccesfull.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; &lt;STRONG&gt;&lt;I&gt;comment&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; &amp;amp;sysdate &amp;gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="4"&gt;'28FEB16'&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; and &amp;lt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="4"&gt;'30JAN17'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="4"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="4"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; cmt=*;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;comment&lt;/I&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; &amp;amp;cmt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="4"&gt;My current output from the log is:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;479 %macro comment;&lt;/P&gt;&lt;P&gt;480 %if &amp;amp;sysdate &amp;gt;='28FEB16' and &amp;lt;'30JAN17' %then %let cmt=*;&lt;/P&gt;&lt;P&gt;481&lt;/P&gt;&lt;P&gt;482 %mend;&lt;/P&gt;&lt;P&gt;483 %comment;&lt;/P&gt;&lt;P&gt;SYMBOLGEN: Macro variable SYSDATE resolves to 28DEC16&lt;/P&gt;&lt;P&gt;484 %put &amp;amp;cmt;&lt;/P&gt;&lt;P&gt;WARNING: Apparent symbolic reference CMT not resolved.&lt;/P&gt;&lt;P&gt;&amp;amp;cmt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the &amp;amp;cmt to turin into *.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any direction would be much apprecated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2016 22:16:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321492#M71008</guid>
      <dc:creator>yo1</dc:creator>
      <dc:date>2016-12-28T22:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321495#M71009</link>
      <description>&lt;P&gt;The following is not valid SAS code, either in macro or a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;sysdate &amp;gt;='28FEB16' and &amp;lt;'30JAN17'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As is, SAS will do a text comparsion when you want a date comparison.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps something like the following, making sure to declare a global macro variable for cmt and set it to blank so you don't get previous values hanging around. For comparing dates you should use %sysevalf to make the numeric comparison. There may be another way to do the date comparisons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro comment;

%global cmt;
%let cmt=;

%if %sysevalf("&amp;amp;sysdate"d &amp;gt;='28FEB2016'd) and %sysevalf("&amp;amp;sysdate"d&amp;lt;'30JAN2017'd) %then %let cmt=*;

%mend;

%comment;

%put &amp;amp;cmt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2016 22:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321495#M71009</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-28T22:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321496#M71010</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if "&amp;amp;sysdate"d &amp;gt;= "28feb2016"d and "&amp;amp;sysdate"d &amp;lt; "30jan2017"d
then call symput('cmt','*');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's much easier in a data step.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2016 22:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321496#M71010</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-28T22:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321499#M71011</link>
      <description>&lt;P&gt;And if you use CALL SYMPUTX the third parameter creates a global macro variable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2016 23:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321499#M71011</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-28T23:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321500#M71012</link>
      <description>&lt;P&gt;Yes, it is far easier (especially when reviewing the code the next day)&amp;nbsp;in a data step, but sometimes you want inline macro code that doesn't require a data step or even a user-defined macro call.&amp;nbsp; This macrovar assignment can be used in open code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%let&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; cmt=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(ifc(&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(01jan2017,date9.))&amp;lt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(&amp;amp;sysdate,date9.))&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;and&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; %sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(&amp;amp;sysdate,date9.))&amp;lt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(31jan2017,date9.))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;,*,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%str&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;( )));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%put&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; &amp;amp;=cmt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or maybe a parameterized macro call:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; cmt(dat1,dat2);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; %if&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(&amp;amp;dat1,&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;))&amp;lt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(&amp;amp;sysdate,&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;)) and&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Sasfont"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(&amp;amp;sysdate,&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;))&amp;lt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;(inputn(&amp;amp;dat2,&lt;/FONT&gt;&lt;FONT color="#008080" face="Sasfont"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; %then&lt;/FONT&gt; &lt;FONT color="#008000" face="Sasfont"&gt;*;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;&amp;nbsp; %else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Sasfont"&gt;%str&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;( )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Sasfont"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Sasfont"&gt;%let&lt;/FONT&gt;&lt;FONT face="Sasfont"&gt; cmt=%cmt(01feb2016,31jan2017);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know - lots and lots of %SYSFUNCs, but just for completeness.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2016 00:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321500#M71012</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-12-29T00:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321590#M71049</link>
      <description>&lt;P&gt;KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your post. This gave me the answer I was looking for.&amp;nbsp; The code provided&amp;nbsp;is simplier to perform.&amp;nbsp; The main goal for this task was to comment out certain parts of code within&amp;nbsp;my main program so that certain&amp;nbsp;data tables would not get overwritten in case someone needed to run the process again. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Happy Holidays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2016 14:57:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321590#M71049</guid>
      <dc:creator>yo1</dc:creator>
      <dc:date>2016-12-29T14:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321592#M71050</link>
      <description>&lt;P&gt;Hello Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your post.&amp;nbsp; Your reponse gave me the answer I was looking for.&amp;nbsp; The main purpose for this task is to remove certain parts of code within a time period so that specific data tables wouldn't get overwritten.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Big thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Dec 2016 14:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321592#M71050</guid>
      <dc:creator>yo1</dc:creator>
      <dc:date>2016-12-29T14:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: creating conditions using date range and generating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321594#M71051</link>
      <description>Thanks mkeintz. Your code works as well. Its great to have variety of code for a specific task because one may run into a certain situations where one method works better (or more efficient) than others.&lt;BR /&gt;&lt;BR /&gt;Happy Holidays.</description>
      <pubDate>Thu, 29 Dec 2016 15:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-conditions-using-date-range-and-generating-a-macro/m-p/321594#M71051</guid>
      <dc:creator>yo1</dc:creator>
      <dc:date>2016-12-29T15:02:29Z</dc:date>
    </item>
  </channel>
</rss>

