<?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: Custom datestamp in the output filename in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850960#M336299</link>
    <description>That is correct. I created max_date based on the date variable not shown&lt;BR /&gt;here (which has a different date for each record). So max is max for all&lt;BR /&gt;records. My aim was to produce file name based on each quarterly data, so&lt;BR /&gt;that once the report is automated the file name tells which quarter and&lt;BR /&gt;year the data belongs to.&lt;BR /&gt;</description>
    <pubDate>Fri, 23 Dec 2022 15:07:41 GMT</pubDate>
    <dc:creator>bijayadhikar</dc:creator>
    <dc:date>2022-12-23T15:07:41Z</dc:date>
    <item>
      <title>Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850953#M336296</link>
      <description>&lt;P&gt;Happy holidays!&lt;/P&gt;
&lt;P&gt;I am trying to put custom year and quarter in the output file name using variables in the dataset (i.e. year and quart), and NOT using&amp;nbsp; macro date function. Output file will be saved in the &lt;STRONG&gt;libname qc&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Desired&lt;/STRONG&gt; output file name should be&amp;nbsp;&lt;STRONG&gt;report_2022_3&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I tried the following script but it uses sysdate year and quarter, and gives&amp;nbsp;&lt;STRONG&gt;report_2022_&lt;FONT color="#FF0000"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input caseid $ max_Date date9. year quart;&lt;BR /&gt;format max_Date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;34 27jul2022 2022 3&lt;BR /&gt;35 27jul2022 2022 3&lt;BR /&gt;37 27jul2022 2022 3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data repstamps;&lt;BR /&gt;max_Date = "&amp;amp;sysdate9."d;&lt;BR /&gt;rep_qtr = qtr(max_Date );&lt;BR /&gt;rep_year = year(max_Date );&lt;BR /&gt;call symput('rep_qtr',put(rep_qtr,1.));&lt;BR /&gt;call symput('rep_year',put(rep_year,4.));&lt;/P&gt;
&lt;P&gt;run;&lt;BR /&gt;%put &amp;amp;rep_qtr;&lt;BR /&gt;%put &amp;amp;rep_year;&lt;/P&gt;
&lt;P&gt;%let out = report&amp;amp;rep_qtr;&lt;BR /&gt;data qc.report_&amp;amp;rep_qtr._&amp;amp;rep_year;&lt;BR /&gt;set precom;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2022 14:43:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850953#M336296</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2022-12-23T14:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850955#M336297</link>
      <description>&lt;P&gt;Are your dates in the HAVE dataset the same for every record? &amp;nbsp;If so, you can read one record from that dataset, and use it as the source for your macro variables, e.g. (untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data repstamps;
  set have (keep=max_Date obs=1);
  * max_Date = "&amp;amp;sysdate9."d;
  rep_qtr = qtr(max_Date );
  rep_year = year(max_Date );
  call symput('rep_qtr',put(rep_qtr,1.));
  call symput('rep_year',put(rep_year,4.));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Dec 2022 14:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850955#M336297</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-12-23T14:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850960#M336299</link>
      <description>That is correct. I created max_date based on the date variable not shown&lt;BR /&gt;here (which has a different date for each record). So max is max for all&lt;BR /&gt;records. My aim was to produce file name based on each quarterly data, so&lt;BR /&gt;that once the report is automated the file name tells which quarter and&lt;BR /&gt;year the data belongs to.&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Dec 2022 15:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850960#M336299</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2022-12-23T15:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850961#M336300</link>
      <description>Sorry there was typo. the SET statement should read file have, not precom.</description>
      <pubDate>Fri, 23 Dec 2022 15:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850961#M336300</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2022-12-23T15:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850962#M336301</link>
      <description>&lt;P&gt;Use the variables in your dataset instead of taking the date from the when the SAS session started.&lt;/P&gt;
&lt;P&gt;If you really have this dataset&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input caseid $ max_Date date9. year quart;
  format max_Date date9.;
datalines;
34 27jul2022 2022 3
35 27jul2022 2022 3
37 27jul2022 2022 3
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;, where the YEAR and QUART are constants, then it does not matter which observation you use.&lt;/P&gt;
&lt;P&gt;So use the first one.&amp;nbsp; Note there is no reason to use the ancient CALL SYMPUT() function unless you actually need to store leading or trailing spaces into the generated macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have;
  call symputx('rep_qtr',quart);
  call symputx('rep_year',year);
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2022 15:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850962#M336301</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-23T15:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850963#M336302</link>
      <description>Thank you Quentin.&lt;BR /&gt;This is exactly what I wanted.</description>
      <pubDate>Fri, 23 Dec 2022 15:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850963#M336302</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2022-12-23T15:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Custom datestamp in the output filename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850964#M336303</link>
      <description>Thank you Tom. I tested your scripts, and it did work as well.&lt;BR /&gt;Much appreciated.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 23 Dec 2022 15:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Custom-datestamp-in-the-output-filename/m-p/850964#M336303</guid>
      <dc:creator>bijayadhikar</dc:creator>
      <dc:date>2022-12-23T15:29:41Z</dc:date>
    </item>
  </channel>
</rss>

