<?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 do I can write macro program with date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515385#M139040</link>
    <description>&lt;P&gt;This type of logic works in a data step but does not work in the macro language&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %if "31DEC2017"d   &amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31MAR2018"d &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You'll also likely have to use %EVAL or %SYSEVALF to get it to be correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably easier to do this in a data _null_ step rather than a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I am trying to assign different value to macro "&lt;SPAN&gt;dt_rif_short_Ifrs9"&amp;nbsp;depending on the "dt_riferimento" macro value but the macro program seems doesn't work correctly. (for example if &amp;amp;dt_riferimento =&amp;nbsp;"31MAR2018"d, &amp;amp;dt_rif_short_Ifrs9&amp;nbsp; =&amp;nbsp;201709 and not&amp;nbsp;31MAR2018 as I want).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you know why? I think there is some problems with date value...let me know.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am using SAS University Edition.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for your time and help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Daniele&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;%let dt_riferimento = "31MAR2018"d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;macro ifrs9 ();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; %global dt_rif_short_Ifrs9;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if "31DEC2017"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31MAR2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201709;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "31MAR2018"d&amp;nbsp; &amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"30JUN2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201803;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "30JUN2018"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"30SEP2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201806;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "30SEP2018"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"31DEC2018"d&amp;nbsp; %then %let dt_rif_short_Ifrs9 = 201809;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%else %let dt_rif_short_Ifrs9= "error";&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%&lt;SPAN&gt;ifrs9&amp;nbsp;&lt;/SPAN&gt;();&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%put the value of the macro variable dt_rif_short_Ifrs9 is: &amp;amp;dt_rif_short_Ifrs9.;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Nov 2018 15:51:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-22T15:51:26Z</dc:date>
    <item>
      <title>How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515312#M139009</link>
      <description>&lt;P&gt;Hi, I am trying to assign different value to macro "&lt;SPAN&gt;dt_rif_short_Ifrs9"&amp;nbsp;depending on the "dt_riferimento" macro value but the macro program seems doesn't work correctly. (for example if &amp;amp;dt_riferimento =&amp;nbsp;"31MAR2018"d, &amp;amp;dt_rif_short_Ifrs9&amp;nbsp; =&amp;nbsp;201709 and not&amp;nbsp;31MAR2018 as I want).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do you know why? I think there is some problems with date value...let me know.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am using SAS University Edition.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your time and help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Daniele&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;%let dt_riferimento = "31MAR2018"d;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;macro ifrs9 ();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; %global dt_rif_short_Ifrs9;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if "31DEC2017"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31MAR2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201709;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "31MAR2018"d&amp;nbsp; &amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"30JUN2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201803;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "30JUN2018"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"30SEP2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201806;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "30SEP2018"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"31DEC2018"d&amp;nbsp; %then %let dt_rif_short_Ifrs9 = 201809;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%else %let dt_rif_short_Ifrs9= "error";&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%&lt;SPAN&gt;ifrs9&amp;nbsp;&lt;/SPAN&gt;();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%put the value of the macro variable dt_rif_short_Ifrs9 is: &amp;amp;dt_rif_short_Ifrs9.;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 09:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515312#M139009</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2018-11-22T09:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515314#M139010</link>
      <description>&lt;P&gt;Macro is a text based find and replace system.&amp;nbsp; As it is text, all text is evaluated as text.&amp;nbsp; Dates and such like do not exist in macro.&amp;nbsp; You can force a numeric comparison by use of the %eval() function, however I really think the problem here is the misuse of macro language.&amp;nbsp; It is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;Not&lt;/STRONG&gt;&lt;/U&gt; a replace for base sas coding.&amp;nbsp; It is a separate text generation tool for a specific purpose, not to re implement Base SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tells us what your trying to do, what inputs and outputs you have (i.e. what you have, and what you want).&amp;nbsp; You will want to do your logic and data processing in datastep, e.g:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let dt_riferimento=31MAR2018;

data want;
  set have;
  if "31DEC2017"d &amp;lt;= "&amp;amp;dt_riferimento."d &amp;lt; "31MAR2018"d then...
...
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Nov 2018 09:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515314#M139010</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-22T09:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515316#M139011</link>
      <description>&lt;P&gt;The macro preprocessor is not good for handling data, as it is meant to only create program &lt;EM&gt;text&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the proper tool, which is a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if "31DEC2017"d &amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31MAR2018"d then dt_rif_short_Ifrs9 = "201709";
else if "31MAR2018"d &amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "30JUN2018"d then dt_rif_short_Ifrs9 = "201803";
else if "30JUN2018"d &amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "30SEP2018"d then dt_rif_short_Ifrs9 = "201806";
else if "30SEP2018"d &amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31DEC2018"d then dt_rif_short_Ifrs9 = "201809";
else dt_rif_short_Ifrs9 = 'error';
call symputx('dt_rif_short_Ifrs9',dt_rif_short_Ifrs9,'g');
run;

%put &amp;amp;dt_rif_short_Ifrs9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log excerpt:&lt;/P&gt;
&lt;PRE&gt;36         %put &amp;amp;dt_rif_short_Ifrs9;
201803
&lt;/PRE&gt;
&lt;P&gt;Shouldn't the value for the first condition be "201712"? If that were true, you can replace the whole if-then-else-if avalanche with a formula.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 09:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515316#M139011</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-22T09:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515341#M139023</link>
      <description>&lt;P&gt;I agree completely with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;.&amp;nbsp;This could be the set of formulas you use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*************** TEST DATA ***************/

data tests;
	attrib TestDate format = date9.;
	do TestDate = "15Dec2017"d to "15Dec2018"d by 14;
		output;
	end;
run;

/*** Demonstrates how the process works using test data ***/
data testingdates;
	set tests;
	attrib wantDate firstDayOfWantDate format = date9.;
	/*find month and year*/
	dateMonth = month(TestDate);
	dateYear = year(TestDate);
	/*modify month to find the group month*/
	outputMonth = 2 + dateMonth - mod(dateMonth - 1,3);
	/*create a date using the year and modified date*/
	firstDayOfWantDate = mdy(OutputMonth,1,dateYear);
	/*find the date of the end of the month of the created date*/
	wantDate = intnx('month',firstDayOfWantDate,0,'end');
run;

/*************** WANT ***************/

%let dt_riferimento=12JAN2016;

data _null_;
TestDate = "&amp;amp;dt_riferimento"d;

	/*find month and year*/
	dateMonth = month(TestDate);
	dateYear = year(TestDate);
	/*modify month to find the group month*/
	outputMonth = 2 + dateMonth - mod(dateMonth - 1,3);
	/*create a date using the year and modified date*/
	firstDayOfWantDate = mdy(OutputMonth,1,dateYear);
	/*find the date of the end of the month of the created date*/
	wantDate = intnx('month',firstDayOfWantDate,0,'end');
	/*format the date how you want*/
	FormatWantDate = coalescec( put(wantDate,date9.) ,'error');

CALL SYMPUTX('dt_rif_short_Ifrs9',FormatWantDate,'G');
run;

%PUT dt_rif_short_Ifrs9 = &amp;amp;dt_rif_short_Ifrs9;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It includes some examples and the method that produces what you want.&lt;/P&gt;&lt;P&gt;If it specifically needs to be between those particular dates you could then use a formula at the end to turn it into the error value you want.&lt;/P&gt;&lt;P&gt;You might also want to look into&amp;nbsp;using custom formats to do this.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 13:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515341#M139023</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2018-11-22T13:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515385#M139040</link>
      <description>&lt;P&gt;This type of logic works in a data step but does not work in the macro language&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %if "31DEC2017"d   &amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31MAR2018"d &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You'll also likely have to use %EVAL or %SYSEVALF to get it to be correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably easier to do this in a data _null_ step rather than a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I am trying to assign different value to macro "&lt;SPAN&gt;dt_rif_short_Ifrs9"&amp;nbsp;depending on the "dt_riferimento" macro value but the macro program seems doesn't work correctly. (for example if &amp;amp;dt_riferimento =&amp;nbsp;"31MAR2018"d, &amp;amp;dt_rif_short_Ifrs9&amp;nbsp; =&amp;nbsp;201709 and not&amp;nbsp;31MAR2018 as I want).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Do you know why? I think there is some problems with date value...let me know.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am using SAS University Edition.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for your time and help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Daniele&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;%let dt_riferimento = "31MAR2018"d;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;macro ifrs9 ();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; %global dt_rif_short_Ifrs9;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if "31DEC2017"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt; "31MAR2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201709;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "31MAR2018"d&amp;nbsp; &amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"30JUN2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201803;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "30JUN2018"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"30SEP2018"d&amp;nbsp; &amp;nbsp;%then %let dt_rif_short_Ifrs9 = 201806;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %if "30SEP2018"d&amp;nbsp; &amp;nbsp;&amp;lt;= &amp;amp;dt_riferimento. &amp;lt;&amp;nbsp; &amp;nbsp;"31DEC2018"d&amp;nbsp; %then %let dt_rif_short_Ifrs9 = 201809;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%else %let dt_rif_short_Ifrs9= "error";&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;%&lt;SPAN&gt;ifrs9&amp;nbsp;&lt;/SPAN&gt;();&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%put the value of the macro variable dt_rif_short_Ifrs9 is: &amp;amp;dt_rif_short_Ifrs9.;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 15:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515385#M139040</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-22T15:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515519#M139099</link>
      <description>&lt;P&gt;To get the macro to evaluate the dates correctly, you should use %SYSEVALF.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then there is the other problem: SAS Macro language does not understand a&amp;lt;=b&amp;lt;c the same way as the datastep. Instead of translating it to "a&amp;lt;=b and b&amp;lt;c" it resolves it to "(a&amp;lt;=b)&amp;lt;c". And (a&amp;lt;=b) always resolves to 1 (true) or 0 (false). And if c is a recent date value, the total comparison always comes out as 1 (true).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I think you should avoid declaring %GLOBAL macro variables inside a macro, if you can. And in this case, you can. Just rewrite the macro as a macro function, like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ifrs9 (dt);
    %if %sysevalf(&amp;amp;dt &amp;lt; "31DEC2017"d) %then %do;error%end; 
    %else %if %sysevalf(&amp;amp;dt &amp;lt; "31MAR2018"d)   %then %do;201709%end;
    %else %if %sysevalf(&amp;amp;dt &amp;lt;  "30JUN2018"d) %then %do;201803%end;
    %else %if %sysevalf(&amp;amp;dt &amp;lt;  "30SEP2018"d) %then %do;201806%end;
    %else %if %sysevalf(&amp;amp;dt &amp;lt;  "31DEC2018"d) %then %do;201809%end;
    %else %do;error%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I put all the %do...%end stuff in to avoid spurious blanks and hanging semicolons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you use the macro like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dt_riferimento = "31MAR2018"d;
%let dt_rif_short_Ifrs9=%ifrs9(&amp;amp;dt_riferimento);
%put the value of the macro variable dt_rif_short_Ifrs9 is: &amp;amp;dt_rif_short_Ifrs9.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or you can just use it like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put The IFRS9 value is %ifrs9(&amp;amp;dt_riferimento);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(If you are not referring to your calculated macro variable a lot of times, you can just put the macro call in where you need the value)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 11:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515519#M139099</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-11-23T11:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515543#M139114</link>
      <description>&lt;P&gt;Thanks I have just tried your solution and it works. Great!&lt;/P&gt;&lt;P&gt;ps yes, the value of the first condition is supposed to be&amp;nbsp;&lt;SPAN&gt;"201712".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 13:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515543#M139114</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2018-11-23T13:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515547#M139115</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175761"&gt;@Ccasagran737&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ps yes, the value of the first condition is supposed to be&amp;nbsp;&lt;SPAN&gt;"201712".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In which case you should take a closer look at &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209943"&gt;@DanielLangley&lt;/a&gt;'s suggestion. I would work along the same lines of thinking.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 14:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515547#M139115</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-23T14:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I can write macro program with date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515706#M139188</link>
      <description>&lt;P&gt;Thanks....I have found your advice very intresting.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Nov 2018 06:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-can-write-macro-program-with-date/m-p/515706#M139188</guid>
      <dc:creator>Ccasagran737</dc:creator>
      <dc:date>2018-11-24T06:10:49Z</dc:date>
    </item>
  </channel>
</rss>

