<?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: display a macro date variable in date format with %put in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/608068#M176910</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you want to make computations and use data step functions, it will be easier and make the code&lt;/P&gt;
&lt;P&gt;more readable to do so in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
    start_year=symgetn("year1");
    end_year=symgetn("year2");

    nyear=end_year-start_year+1;
    xmonths=12*nyear;

    do year=start_year to end_year;
        do month=1 to 12;
            date2=intnx('month', mdy(month,1,year), -1, 'end');
            date1=intnx('month', date2, 1-xmonths, 'begin');
            date3=intnx('month', date2, 1, 'begin');

            put "................. Period: " date1 yymmddd10. " -------&amp;gt; " date2 yymmddd10. ".................";
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Nov 2019 15:28:29 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-11-28T15:28:29Z</dc:date>
    <item>
      <title>display a macro date variable in date format with %put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/607977#M176856</link>
      <description>&lt;P&gt;I have a macro that does rolling regression. For each regression, it takes a long time so I would like to look at the LOG and know what period it is regressing.&amp;nbsp; I use the function %PUT to display the period start and end. However, this displays the actual number of datetime variable without formatting. So how do I ask SAS to format and display those date variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My codes are :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Loop for years and months*/
%do yy = &amp;amp;year1 %to &amp;amp;year2;
	%do mm = 1 %to 12;&lt;BR /&gt;
	/*Set date2 for mm-yy end point and date1 as 24 months prior*/
	%let xmonths= %eval(12 * &amp;amp;nyear); *Sample period length in months;
	%let date2=%sysfunc(mdy(&amp;amp;mm,1,&amp;amp;yy));
	%let date2= %sysfunc (intnx(month, &amp;amp;date2, -1,end)); *Make the DATE2 last day of the month;
	%let date1 = %sysfunc (intnx(month, &amp;amp;date2, -&amp;amp;xmonths+1, begin)); *set DATE1 as first (begin) day;
	%let date3 = %sysfunc (intnx(month, &amp;amp;date2, 1, begin));
	/*FYI --- INTNX quirk in SYSFUNC:  do not use quotes with 'month' 'end' and 'begin'*/
	/*An extra step to be sure the loop starts with a clean (empty) dataset for combining results*/
	%put ................. Period: &amp;amp;date1. -------&amp;gt; &amp;amp;date2. .................;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 06:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/607977#M176856</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2019-11-28T06:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: display a macro date variable in date format with %put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/607989#M176866</link>
      <description>&lt;P&gt;Add %sysfunc(putn(&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %put ................. Period: %sysfunc(putn(&amp;amp;date1.,yymmddd10.)) -------&amp;gt; %sysfunc(putn(&amp;amp;date2.,yymmddd10.)) .................;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Nov 2019 07:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/607989#M176866</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-28T07:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: display a macro date variable in date format with %put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/608068#M176910</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you want to make computations and use data step functions, it will be easier and make the code&lt;/P&gt;
&lt;P&gt;more readable to do so in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
    start_year=symgetn("year1");
    end_year=symgetn("year2");

    nyear=end_year-start_year+1;
    xmonths=12*nyear;

    do year=start_year to end_year;
        do month=1 to 12;
            date2=intnx('month', mdy(month,1,year), -1, 'end');
            date1=intnx('month', date2, 1-xmonths, 'begin');
            date3=intnx('month', date2, 1, 'begin');

            put "................. Period: " date1 yymmddd10. " -------&amp;gt; " date2 yymmddd10. ".................";
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Nov 2019 15:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/display-a-macro-date-variable-in-date-format-with-put/m-p/608068#M176910</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-28T15:28:29Z</dc:date>
    </item>
  </channel>
</rss>

