<?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 calculate start of month and end of month macro vars in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892633#M352564</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define 2 macro variables in format YYMM.&lt;/P&gt;
&lt;P&gt;The task is to create 2 more macro variables that are calculated automatically.&lt;/P&gt;
&lt;P&gt;What is the way to calculate them please?&lt;/P&gt;
&lt;P&gt;First macro var will get value of start of month of&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;From_YYMM&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Second macro var will get value of End of month of&amp;nbsp; &lt;CODE class=" language-sas"&gt;until_YYMM&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***USer Define macro variables***/
%let From_YYMM=2212;
%let until_YYMM=2307;

/***Macro variables that need to be calculated automatically***/
%let FROM='01DEC2022'd;
%let Until='31JUL2023'd;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Sep 2023 21:02:08 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2023-09-04T21:02:08Z</dc:date>
    <item>
      <title>calculate start of month and end of month macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892633#M352564</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define 2 macro variables in format YYMM.&lt;/P&gt;
&lt;P&gt;The task is to create 2 more macro variables that are calculated automatically.&lt;/P&gt;
&lt;P&gt;What is the way to calculate them please?&lt;/P&gt;
&lt;P&gt;First macro var will get value of start of month of&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;From_YYMM&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Second macro var will get value of End of month of&amp;nbsp; &lt;CODE class=" language-sas"&gt;until_YYMM&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/***USer Define macro variables***/
%let From_YYMM=2212;
%let until_YYMM=2307;

/***Macro variables that need to be calculated automatically***/
%let FROM='01DEC2022'd;
%let Until='31JUL2023'd;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Sep 2023 21:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892633#M352564</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-09-04T21:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: calculate start of month and end of month macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892634#M352565</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let from = %sysfunc(inputn(20&amp;amp;from_yymm.01,yymmdd8.));
%let until = %sysfunc(intnx(month,%sysfunc(inputn(20&amp;amp;until_yymm.01,yymmdd8.)),0,e));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Sep 2023 21:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892634#M352565</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-04T21:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: calculate start of month and end of month macro vars</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892637#M352568</link>
      <description>&lt;P&gt;I'd suggest:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let from_date=%sysfunc(putn(%sysfunc(inputn(20&amp;amp;from_yymm.01,yymmdd8.)),date9.));
%let until_date=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(inputn(20&amp;amp;until_yymm.01,yymmdd8.)),0,e)),date9.));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will produce macrovars&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;GLOBAL FROM_DATE 01DEC2022
GLOBAL FROM_YYMM 2212
GLOBAL UNTIL_DATE 31JUL2023
GLOBAL UNTIL_YYMM 2307

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think eliminating the single quotes makes things simpler.&amp;nbsp; FROM_DATE and UNTIL_DATE are human-readable, while allowing this usage in your regular SAS code.&amp;nbsp; Just use double-quotes (which will not mask the value from the macro interpreter) and the trailing letter &lt;EM&gt;&lt;STRONG&gt;d&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date between "&amp;amp;from_date"d and "&amp;amp;to_date"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 22:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-start-of-month-and-end-of-month-macro-vars/m-p/892637#M352568</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-04T22:09:22Z</dc:date>
    </item>
  </channel>
</rss>

