<?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 add date to dataset name in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565503#M11184</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a date to the name of a dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This date (reference_date) has been defined somewhere in the beginning of my code.&lt;/P&gt;
&lt;P&gt;In the example in the following code, I would like to have a tablename like "RESULTS_2005_010519"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code did not work, what could be wrong with it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro backup_results;

%let reference_date= '1MAY2019'd;

/* other code */

data test.RESULTS_2005_%sysfunc(datepart(%sysfunc(input(&amp;amp;reference_date.,DDMMYY10.))));
set test.RESULTS_2005;
run;


%mend;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 12 Jun 2019 10:41:46 GMT</pubDate>
    <dc:creator>fre</dc:creator>
    <dc:date>2019-06-12T10:41:46Z</dc:date>
    <item>
      <title>add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565503#M11184</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a date to the name of a dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This date (reference_date) has been defined somewhere in the beginning of my code.&lt;/P&gt;
&lt;P&gt;In the example in the following code, I would like to have a tablename like "RESULTS_2005_010519"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code did not work, what could be wrong with it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro backup_results;

%let reference_date= '1MAY2019'd;

/* other code */

data test.RESULTS_2005_%sysfunc(datepart(%sysfunc(input(&amp;amp;reference_date.,DDMMYY10.))));
set test.RESULTS_2005;
run;


%mend;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 10:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565503#M11184</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2019-06-12T10:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565504#M11185</link>
      <description>&lt;P&gt;The string....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token datetime number"&gt;'1MAY2019'd&lt;/SPAN&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...doesn't convert to a SAS date the way you pass it to the SAS macro variable. It's just exactly the string. For this reason your %sysfunc() stuff is not going to work as it expects a SAS data value.&lt;/P&gt;
&lt;P&gt;Also: If it would be a SAS date value then there is no reason to use the datepart() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question: Is the string as passed to &amp;amp;reference_date a given or can you change this? Your answer will drive where the code change needs to be applied.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here an approach if you can't change &amp;amp;reference_date&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let reference_date= '01MAY2019'd;

data _null_;
  call symputx('reference_date_2',&amp;amp;reference_date);
  stop;
run;
%put &amp;amp;=reference_date_2;

data test_2005_%sysfunc(putn(&amp;amp;reference_date_2.,DDMMYYn8.));
  set sashelp.class;
run;

proc contents data=_last_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually true,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;is right. Using the string in the putn() function is already enough for SAS to first convert it to a SAS date value.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 11:11:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565504#M11185</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-12T11:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565506#M11186</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro backup_results;

%let reference_date= '1MAY2019'd;

/* other code */

data RESULTS_2005_%sysfunc(putn(&amp;amp;reference_date.,DDMMYYn6.));
set sashelp.class;
run;


%mend;

%backup_results&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 11:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565506#M11186</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-12T11:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565514#M11188</link>
      <description>&lt;P&gt;Thank you Ksharp &amp;amp; Patrick for giving me more insight into this matter.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 11:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565514#M11188</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2019-06-12T11:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565515#M11189</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28934"&gt;@fre&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to add a date to the name of a dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This date (reference_date) has been defined somewhere in the beginning of my code.&lt;/P&gt;
&lt;P&gt;In the example in the following code, I would like to have a tablename like "RESULTS_2005_010519"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code did not work, what could be wrong with it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro backup_results;

%let reference_date= '1MAY2019'd;

/* other code */

data test.RESULTS_2005_%sysfunc(datepart(%sysfunc(input(&amp;amp;reference_date.,DDMMYY10.))));
set test.RESULTS_2005;
run;


%mend;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Multiple things&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;do not apply the datepart() function to a date. datepart() is for extracting dates from &lt;EM&gt;datetimes&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;you already specified a &lt;EM&gt;date literal&lt;/EM&gt;, so no input function is necessary&lt;/LI&gt;
&lt;LI&gt;to display a date in a specified format within macro code, use the putn() function&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let reference_date= '1MAY2019'd;
%put %sysfunc(putn(&amp;amp;reference_date.,DDMMYY10.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I would strongly recommend, when time-stamping files or datasets, to use the ymd order for your date:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test.RESULTS_2005_%sysfunc(putn(&amp;amp;reference_date.,yymmddd10.));
set test.RESULTS_2005;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because then everything sorts chronologically on its own.&lt;/P&gt;
&lt;P&gt;Also note that I put dashes into the timestamp instead of slashes (that's the third "d" in the format), as that won't confuse your filesystem syntax.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 11:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565515#M11189</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-12T11:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565527#M11194</link>
      <description>&lt;P&gt;Thank you Kurt for your clarification.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can understand your advice of using the ymd order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, I've adapted my code from:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test.RESULTS_2005_%sysfunc(putn(&amp;amp;reference_date.,DDMMYYn6.));  /* solution provided by Ksharp, which works */&lt;/PRE&gt;
&lt;P&gt;to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test.RESULTS_2005_%sysfunc(putn(&amp;amp;reference_date.,yymmddd10.)); /* solution by Kurt =&amp;gt; error */&lt;/PRE&gt;
&lt;P&gt;The error I get after this change is ERROR 22-322:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_. &lt;BR /&gt;76: LINE and COLUMN cannot be determined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not understand why changing the format from &lt;STRONG&gt;DDMMYYn6.&lt;/STRONG&gt; to &lt;STRONG&gt;yymmddd10.&lt;/STRONG&gt; induces this error.&amp;nbsp; Do you?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 12:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565527#M11194</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2019-06-12T12:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565529#M11195</link>
      <description>&lt;P&gt;My bad.One can't have dashes in dataset names, only in filenames. Remove the dashes altogether:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test.RESULTS_2005_%sysfunc(putn(&amp;amp;reference_date.,yymmddn8.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 12:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565529#M11195</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-12T12:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: add date to dataset name</title>
      <link>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565538#M11196</link>
      <description>&lt;P&gt;Thank you Kurt, it's working now like it should.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 12:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/add-date-to-dataset-name/m-p/565538#M11196</guid>
      <dc:creator>fre</dc:creator>
      <dc:date>2019-06-12T12:38:31Z</dc:date>
    </item>
  </channel>
</rss>

