<?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: Renaming a dataset during a proc copy with datetime in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395868#M95545</link>
    <description>&lt;P&gt;Something like below could do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.abc1;
  set sashelp.class;
run;
data work.abc2;
  set sashelp.class;
run;
data work.abcXXXXXXXXXXXXXXXXXXXXXXX;
  set sashelp.class;
run;

%let dttm=%sysfunc(datetime());
proc sql noprint;
  select
    memname, cats(memname,'=',memname,'_',put(&amp;amp;dttm,b8601dt.)) 
      into 
        :cp_list separated by ' ',
        :rn_list separated by ' '
  from dictionary.tables
  where 
    libname='WORK' 
    and memname like 'ABC%'
    /* only select DS names which don't get longer than 32 characters */
    and length(cats(memname,'=',memname,'_',put(&amp;amp;dttm,b8601dt.)))&amp;lt;=32
  ;
quit;

%put %nrbquote(&amp;amp;=cp_list);
%put %nrbquote(&amp;amp;=rn_list);

libname outds 'c:\temp';
proc datasets lib=outds nolist;
  copy in=work out=outds;
    select &amp;amp;cp_list;
  run;
  change &amp;amp;rn_list;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Sep 2017 09:39:07 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-09-14T09:39:07Z</dc:date>
    <item>
      <title>Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395434#M95396</link>
      <description>&lt;P&gt;(spun off of &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Renaming-a-dataset-during-a-proc-copy/m-p/281434#M57074" target="_self"&gt;this original thread&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to copy all files from one library to another with renaming all of them. For example, XYZ file should be renamed as 'XYZ_datetime'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anybody have any idea how to do that?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 11:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395434#M95396</guid>
      <dc:creator>Bipasha</dc:creator>
      <dc:date>2017-09-13T11:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395558#M95430</link>
      <description>&lt;P&gt;The approaches there, look correct. Which part do you need help with?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 14:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395558#M95430</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-13T14:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395853#M95540</link>
      <description>&lt;P&gt;I have to rename only the files I am copying from the source library (automated approach) &amp;nbsp;with concatenating timestamp with them without affecting existing files in the target library. &amp;nbsp;Also, I don't&amp;nbsp;want to rename the files in the source library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 06:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395853#M95540</guid>
      <dc:creator>Bipasha</dc:creator>
      <dc:date>2017-09-14T06:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395856#M95542</link>
      <description>&lt;P&gt;Before adding a datetime suffix, you have to check and consider the length of your existing dataset name first. &amp;nbsp;SAS is only capable of 32 characters when naming or RENAMING tables and/or columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just how you want the datetime suffix to look like?&lt;/P&gt;&lt;P&gt;Examples:&lt;/P&gt;&lt;P&gt;mmddyy_hhmmss - 13 additional characters&amp;nbsp;&lt;BR /&gt;mmddyyhhmmss&lt;SPAN&gt;- 12 additional characters&lt;/SPAN&gt;&lt;BR /&gt;mmddyyhhmm&lt;SPAN&gt;- 10 additional characters&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OLD dataset name + datetime Suffix &amp;gt; 32 is an automatic error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 07:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395856#M95542</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-14T07:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395859#M95543</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let srclib=SASHELP;
%let tgtlib=WORK;

proc sql noprint;
  create table COPYLIST(where=(length(RENAME) &amp;lt;=32)) as
select MEMNAME, compress(catx("_",MEMNAME,put(datetime(),datetime16.)),":") as
rename from DICTIONARY.TABLES
where
  upcase(LIBNAME)="&amp;amp;srclib." and upcase(MEMTYPE)='DATA';


select count(MEMNAME) into :n from COPYLIST;

%let n=&amp;amp;n.;

select MEMNAME, RENAME into :MEM1-:MEM&amp;amp;n, :REN1-:REN&amp;amp;n. from COPYLIST;

quit;

%macro CopyThenRename;
proc datasets lib=&amp;amp;srclib. nolist;
  copy out=&amp;amp;tgtlib. MT=DATA;
  select %do i=1 %to &amp;amp;n.;  &amp;amp;&amp;amp;mem&amp;amp;i. %end; ;
quit;

proc datasets lib=&amp;amp;tgtlib. nolist;
  change
  %do i=1 %to &amp;amp;n.;
    &amp;amp;&amp;amp;mem&amp;amp;i. = &amp;amp;&amp;amp;ren&amp;amp;i.
  %end; / mt=data;
run;
quit;
%mend;

%CopyThnRname;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 07:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395859#M95543</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-14T07:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395868#M95545</link>
      <description>&lt;P&gt;Something like below could do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.abc1;
  set sashelp.class;
run;
data work.abc2;
  set sashelp.class;
run;
data work.abcXXXXXXXXXXXXXXXXXXXXXXX;
  set sashelp.class;
run;

%let dttm=%sysfunc(datetime());
proc sql noprint;
  select
    memname, cats(memname,'=',memname,'_',put(&amp;amp;dttm,b8601dt.)) 
      into 
        :cp_list separated by ' ',
        :rn_list separated by ' '
  from dictionary.tables
  where 
    libname='WORK' 
    and memname like 'ABC%'
    /* only select DS names which don't get longer than 32 characters */
    and length(cats(memname,'=',memname,'_',put(&amp;amp;dttm,b8601dt.)))&amp;lt;=32
  ;
quit;

%put %nrbquote(&amp;amp;=cp_list);
%put %nrbquote(&amp;amp;=rn_list);

libname outds 'c:\temp';
proc datasets lib=outds nolist;
  copy in=work out=outds;
    select &amp;amp;cp_list;
  run;
  change &amp;amp;rn_list;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 09:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/395868#M95545</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-14T09:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming a dataset during a proc copy with datetime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/429567#M106113</link>
      <description>&lt;P&gt;Thanx Pratick. I have written similar code for the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 09:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-a-dataset-during-a-proc-copy-with-datetime/m-p/429567#M106113</guid>
      <dc:creator>Bipasha</dc:creator>
      <dc:date>2018-01-22T09:16:44Z</dc:date>
    </item>
  </channel>
</rss>

