<?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 How to put monthname as string in output file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77260#M16676</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings all.&amp;nbsp; I am developing a monthly report that needs to be named with the run date, report name, report month and year.&amp;nbsp; For example, if today is 2013-09-10, and I am running the report for August 2013, the output Excel file must be named '2013-09-10 report name Augst 2013.xlsx'.&amp;nbsp; The base data for the report comes from an ODBC query, and I have a macro variable for the begin date, 'dtbegin', and the end date is caclulated.&amp;nbsp; My issue is in create the output file name.&amp;nbsp; I am basically formating the date variables as yymmdd10. so I can pull out the year, month, and day, then building them back into YYYY-MM-DD format.&amp;nbsp; I need to have the dates in yymmdd10. format for the pass through to DB2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*the end date will be calculated, and also need to be in yymmdd10. format ;&lt;/P&gt;&lt;P&gt;%Let dtbegin = '2013-08-01' ;&lt;/P&gt;&lt;P&gt;%Let fpath = 'C:\imports\' ;&lt;/P&gt;&lt;P&gt;data &lt;U&gt;null&lt;/U&gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;add one month to the begin date ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dt2 = intnx('month',input( &amp;amp;dtbegin, yymmdd10.),1) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;get the year, month, and day of dt2, so I can build the ending date in YYYY-MM-DD format ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;there may be an easier way to do this, but this is the only way I could get it to work ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yr = year(dt2) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mo = reverse(substr(cat(trim(reverse(month(dt2))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dy = reverse(substr(cat(trim(reverse(day(dt2))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;put the date components into dtend, which is the other parameter of the pass through query ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;call symput('dtend',cat("'",yr,'-',trim(mo),'-',trim(dy),"'")) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;get the date components of today's date to build the date of the report run for the outfile name ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yr = year(date()) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mo = reverse(substr(cat(trim(reverse(month(date()))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dy = reverse(substr(cat(trim(reverse(day(date()))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;put dtbegin into date format so I can get the year and month for the outfile name ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dt1 = input(&amp;amp;dtbegin, yymmdd10.) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yr2 = year(dt1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mo_name = put(dt1, monname.) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;put all the parts together to build the outfile name ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;call symput('ExcelName',&amp;amp;fpath||cat(yr,'-',trim(mo),'-',trim(dy),' reportname '||trim(mo_name)||' '||trim(yr2)||'.xlsx')) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Show the value of &amp;amp;ExcelName.&amp;nbsp; This issue here is the spaces aroung 'August' and '2013' &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; this will show the issue ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;put "&amp;amp;ExcelName." ;&lt;/P&gt;&lt;P&gt;run ; quit ;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ODBC query with &amp;amp;dtbegin and &amp;amp;dtend in the where clause.&amp;nbsp; This is working ok.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Many more steps here before exporting the Excel file. No issues here.&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;proc export data=final&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outfile="&amp;amp;ExcelName"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbms=excel replace ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sheet='Sheet1' ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Sep 2013 12:16:11 GMT</pubDate>
    <dc:creator>gsnidow</dc:creator>
    <dc:date>2013-09-10T12:16:11Z</dc:date>
    <item>
      <title>How to put monthname as string in output file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77260#M16676</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings all.&amp;nbsp; I am developing a monthly report that needs to be named with the run date, report name, report month and year.&amp;nbsp; For example, if today is 2013-09-10, and I am running the report for August 2013, the output Excel file must be named '2013-09-10 report name Augst 2013.xlsx'.&amp;nbsp; The base data for the report comes from an ODBC query, and I have a macro variable for the begin date, 'dtbegin', and the end date is caclulated.&amp;nbsp; My issue is in create the output file name.&amp;nbsp; I am basically formating the date variables as yymmdd10. so I can pull out the year, month, and day, then building them back into YYYY-MM-DD format.&amp;nbsp; I need to have the dates in yymmdd10. format for the pass through to DB2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*the end date will be calculated, and also need to be in yymmdd10. format ;&lt;/P&gt;&lt;P&gt;%Let dtbegin = '2013-08-01' ;&lt;/P&gt;&lt;P&gt;%Let fpath = 'C:\imports\' ;&lt;/P&gt;&lt;P&gt;data &lt;U&gt;null&lt;/U&gt; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;add one month to the begin date ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dt2 = intnx('month',input( &amp;amp;dtbegin, yymmdd10.),1) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;get the year, month, and day of dt2, so I can build the ending date in YYYY-MM-DD format ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;there may be an easier way to do this, but this is the only way I could get it to work ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yr = year(dt2) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mo = reverse(substr(cat(trim(reverse(month(dt2))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dy = reverse(substr(cat(trim(reverse(day(dt2))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;put the date components into dtend, which is the other parameter of the pass through query ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;call symput('dtend',cat("'",yr,'-',trim(mo),'-',trim(dy),"'")) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;get the date components of today's date to build the date of the report run for the outfile name ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yr = year(date()) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mo = reverse(substr(cat(trim(reverse(month(date()))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dy = reverse(substr(cat(trim(reverse(day(date()))),'0'),1,2)) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;put dtbegin into date format so I can get the year and month for the outfile name ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dt1 = input(&amp;amp;dtbegin, yymmdd10.) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yr2 = year(dt1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mo_name = put(dt1, monname.) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;put all the parts together to build the outfile name ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;call symput('ExcelName',&amp;amp;fpath||cat(yr,'-',trim(mo),'-',trim(dy),' reportname '||trim(mo_name)||' '||trim(yr2)||'.xlsx')) ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Show the value of &amp;amp;ExcelName.&amp;nbsp; This issue here is the spaces aroung 'August' and '2013' &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; this will show the issue ;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;put "&amp;amp;ExcelName." ;&lt;/P&gt;&lt;P&gt;run ; quit ;&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ODBC query with &amp;amp;dtbegin and &amp;amp;dtend in the where clause.&amp;nbsp; This is working ok.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Many more steps here before exporting the Excel file. No issues here.&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;proc export data=final&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;outfile="&amp;amp;ExcelName"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbms=excel replace ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sheet='Sheet1' ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 12:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77260#M16676</guid>
      <dc:creator>gsnidow</dc:creator>
      <dc:date>2013-09-10T12:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to put monthname as string in output file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77261#M16677</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See examples 1 and 2 of the docs for %SYSFUNC. You would probably want to use the MONNAME. format. Or use the MONNAME. format in CALL SYMPUTX.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 12:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77261#M16677</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-09-10T12:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to put monthname as string in output file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77262#M16678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does this not get what you need:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Let dtbegin = '2013-08-01' ;&lt;/P&gt;&lt;P&gt;%Let fpath = 'C:\imports\' ;&lt;/P&gt;&lt;P&gt;data work.test;&lt;/P&gt;&lt;P&gt;dt2=intnx('month',input( &amp;amp;dtbegin, yymmdd10.),1) ;&lt;/P&gt;&lt;P&gt;call symput('fname',cat('',&amp;amp;dtbegin,' report name',put(dt2,monname10.),' ',put(year(dt2),4.),'.xlsx'));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put fname=&amp;amp;fname;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fname= 2013-08-01 report name September 2013.xlsx&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Sep 2013 12:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-monthname-as-string-in-output-file-name/m-p/77262#M16678</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-09-10T12:32:16Z</dc:date>
    </item>
  </channel>
</rss>

