<?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 Formatting a Macro Variable storing a date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782939#M249601</link>
    <description>&lt;P&gt;I am creating a macro variable of the form:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _NULL_;
 ThisDate=Date();
 call symput("FirstDayTwoMonthBack",(IntNX("Month", ThisDate, -2, 'beginning')));
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then when you display the value of this macro variable it is just a "number", i would like to store it as a date format of the type: "2021-11-29" which means year 2021, month = 1, and day = 29.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any advice on how to do this?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Nov 2021 15:55:47 GMT</pubDate>
    <dc:creator>SasStatistics</dc:creator>
    <dc:date>2021-11-29T15:55:47Z</dc:date>
    <item>
      <title>Formatting a Macro Variable storing a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782939#M249601</link>
      <description>&lt;P&gt;I am creating a macro variable of the form:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _NULL_;
 ThisDate=Date();
 call symput("FirstDayTwoMonthBack",(IntNX("Month", ThisDate, -2, 'beginning')));
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then when you display the value of this macro variable it is just a "number", i would like to store it as a date format of the type: "2021-11-29" which means year 2021, month = 1, and day = 29.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any advice on how to do this?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 15:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782939#M249601</guid>
      <dc:creator>SasStatistics</dc:creator>
      <dc:date>2021-11-29T15:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting a Macro Variable storing a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782941#M249602</link>
      <description>&lt;P&gt;usually, it is unnecessary to format a macro variable. the un-formatted macro variable works fine in all logical and arithmetical situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only time you need to format a macro variable is when you are going to use it in a title, label or file name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 16:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782941#M249602</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-29T16:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting a Macro Variable storing a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782942#M249603</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _NULL_;
 ThisDate=Date();
 call symput("FirstDayTwoMonthBack", put(IntNX("Month", ThisDate, -2, 'beginning'), yymmdd10.));
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;%put &amp;amp;FirstDayTwoMonthBack;
2021-09-01
&lt;/PRE&gt;
&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; that this isn't totally necessary, but that gives you what you want I think. &lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 16:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782942#M249603</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-11-29T16:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting a Macro Variable storing a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782946#M249605</link>
      <description>&lt;P&gt;Please remember,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381436"&gt;@SasStatistics&lt;/a&gt;&amp;nbsp;, that if you format the macro variable value, and you want to use it for arithmetic or logical purposes, then you will have to un-format it. That's two operations (formatting followed by un-formatting, and don't forget to do both, and don't get one of the operations wrong) instead of zero operations. Either will work if done properly, it's your choice.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 16:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782946#M249605</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-29T16:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting a Macro Variable storing a date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782982#M249617</link>
      <description>&lt;P&gt;As others already mentioned I would keep it as a number. I would also use CALL SYMPUTX to avoid notes about type conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The functions of the DATA Step can also be used in the SAS macro language using %SYSFUNC. Have a look at the below code sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 ThisDate=Date();
 call symputx("FirstDayTwoMonthBack", IntNX("Month", ThisDate, -2, 'beginning'));

run;
%put NOTE: &amp;amp;FirstDayTwoMonthBack;
%put NOTE: %sysfunc(putn(&amp;amp;FirstDayTwoMonthBack, yymmddd10.));

%let newDate = %sysfunc(intnx(month, %sysfunc(today()), -2, b));
%put NOTE: &amp;amp;=newDate;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 19:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-a-Macro-Variable-storing-a-date/m-p/782982#M249617</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2021-11-29T19:54:29Z</dc:date>
    </item>
  </channel>
</rss>

