<?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 Archiving Data Sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588226#M168084</link>
    <description>&lt;P&gt;I need to move a sas data set from /workspace/data to /workspace/data/archive when it hasn't been used for more than 2 weeks. I need to run the program daily. May I know how to code this?&lt;/P&gt;</description>
    <pubDate>Thu, 12 Sep 2019 13:48:48 GMT</pubDate>
    <dc:creator>iSAS</dc:creator>
    <dc:date>2019-09-12T13:48:48Z</dc:date>
    <item>
      <title>Archiving Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588226#M168084</link>
      <description>&lt;P&gt;I need to move a sas data set from /workspace/data to /workspace/data/archive when it hasn't been used for more than 2 weeks. I need to run the program daily. May I know how to code this?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 13:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588226#M168084</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2019-09-12T13:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Archiving Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588259#M168097</link>
      <description>Cycle thru each of the datasets and check the modify date.  Move it if it's old enough.</description>
      <pubDate>Thu, 12 Sep 2019 14:18:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588259#M168097</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-09-12T14:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Archiving Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588293#M168109</link>
      <description>&lt;P&gt;Define "used". Date&amp;nbsp;Created, modified or read are different ways of defining "used".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can easily get the first two from SAS with code such as:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.junk as
   select memname, libname, crdate, modate
   from dictionary.tables
   where libname='WORK'
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;You can use DATEPART on either of CRDATE or MODATE (both are datetime values) and compare to the TODAY() function value to create code to copy the data sets to a different library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think SAS keeps a "last read" anywhere which would lead to using the external file functions such as DOPEN, DNUM, DREAD, FOPEN, FOPTNUM, FOPTNAME and FINFO.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 15:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588293#M168109</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-12T15:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Archiving Data Sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588310#M168116</link>
      <description>&lt;P&gt;Please try the below code, check the comments for code understanding, i tested it and it worked&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you need to run this everyday manually to move the files, please test and let me know if it helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*use the x command in sas */
x 'ls -l --time-style="+%d/%m/%Y" ~path_of_files*.txt &amp;gt; ~path_of_sample_file_with_list_of_files/sample.txt';

/*get the files that need to be moved to other location*/
proc import datafile='~path_of_sample_file_with_list_of_files/sample.txt' out=test dbms=tab replace;
getnames=no;
run;

data test2;
length files filenames transfer $200.;
set test;
filedate=input(substr(var1,36,10),ddmmyy10.); /*get the file dates*/
filenames=scan(substr(var1,46),8,'/');/*get the filename*/
files=substr(var1,46);/*get the file path*/
today=input("&amp;amp;sysdate9.",date9.);/*todays date*/
format filedate today date9.;
if (today-filedate)&amp;gt;14 then flag=1;/*flag those records where the files are more than 2 weeks old i.e. more than 14 days */
transfer='mv '||strip(files)||" ~new_path_of_files_/"||strip(filenames); /*create a variable with mv i.e., move command to move the flagged files from present location to a differnt location*/
if flag=1 then do;
call execute('x '||strip(transfer)||';');/*call execute to use the x command to move the files*/
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2019 16:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Archiving-Data-Sets/m-p/588310#M168116</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-12T16:00:03Z</dc:date>
    </item>
  </channel>
</rss>

