<?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: dynamically deleting external files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264320#M269220</link>
    <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;your code is basically the same as Reeza's, and I tried it and didn't get the files deleted. Please read my reply to Reeza if you like as it contains more description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
    <pubDate>Sat, 16 Apr 2016 02:11:37 GMT</pubDate>
    <dc:creator>ilikesas</dc:creator>
    <dc:date>2016-04-16T02:11:37Z</dc:date>
    <item>
      <title>dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263387#M269214</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to delete an external file I can use the fdelete funciton in the following way:&lt;/P&gt;
&lt;P&gt;filename delfile 'myfile.test';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; rc=fdelete('delfile');&lt;/P&gt;
&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what I would like to do is to delete files dynamically. I have a data table witht the names and the paths of the files that I want to delete. I tried using the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set files;&lt;/P&gt;
&lt;P&gt;rc = fdelete(path);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But couldn't get the files deleted. I didn't even have an error message, just a blue message saying that "the file ref exceeds 8 characters and will be truncated".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 03:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263387#M269214</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-04-13T03:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263390#M269215</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't use a data _null_ step, save the data set. The RC variable indicates if the delete was successful, check the docs for the return codes that are valid.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about something like the following:&lt;/P&gt;
&lt;P&gt;Courtesy of Joe via&amp;nbsp;&lt;A href="http://stackoverflow.com/questions/13399760/using-sas-to-delete-a-text-file" target="_blank"&gt;http://stackoverflow.com/questions/13399760/using-sas-to-delete-a-text-file&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    fname="tempfile";
    rc=filename(fname,"physical-filename");
    if rc = 0 and fexist(fname) then
       rc=fdelete(fname);
    rc=filename(fname);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 03:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263390#M269215</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-13T03:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263391#M269216</link>
      <description>&lt;P&gt;Also, what kind of files are you deleting?&lt;/P&gt;
&lt;P&gt;I think you asked a very similar question recently or a similar one was on here, you can use call system, %sysexec or an X command to delete the files using OS commands.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 04:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263391#M269216</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-13T04:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263394#M269217</link>
      <description>&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;fdelete&lt;/FONT&gt; function needs a fileref (result of a &lt;FONT face="courier new,courier"&gt;filename&lt;/FONT&gt; statement) as argument, not a physical filename. You need to use the &lt;FONT face="courier new,courier"&gt;filename&lt;/FONT&gt; function first.&lt;/P&gt;
&lt;P&gt;From the examples for &lt;FONT face="courier new,courier"&gt;fdelete&lt;/FONT&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set files;
fname = 'tempref';
rc=filename(fname,path);
if rc = 0 and fexist(fname) then
  rc=fdelete(fname);
rc=filename(fname);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Apr 2016 05:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263394#M269217</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-13T05:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263429#M269218</link>
      <description>&lt;P&gt;Why would you need to remove files from SAS in the first place? &amp;nbsp;SAS output will overwrite anything that is already there, and because you will be using a version control system, you can roll back/commit whatever you need. &amp;nbsp;I have yet to encounter a situation where creating anything on the operating system is necessary for normal day to day work, and those instances where it is necessary this is covered by other procedures - i.e. standard directory strcutures, version control software etc.&lt;/P&gt;
&lt;P&gt;If you do attempt to do it this way, ensure you have a back as there WILL be a time when you program wipes out whole loads of data unexpectedly.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 08:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/263429#M269218</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-13T08:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264319#M269219</link>
      <description>&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Hi Reeza,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;The other question which you are refering to (and which you answered) is the one about creating a folder based on the file names and transfering the files into that folder. But the original files remain, so now I have 2 files: the one which is transfered into the folder, and the original one. So what I would like to achieve is to delete the original files.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;I have a column for the file name and for the file path, and when I run the following code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set filelist;
    
    rc=filename(the_name,the_path);
    if rc = 20014 and fexist(the_name) then
       rc=fdelete(the_name);
    rc=filename(the_name);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;I get a message that the fileref in fexist exceeds 8 characters and will be truncated, and as a result the original files are not deleted.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;I also included quotes for the names and paths (for exampel, a file name in the column the_name is of the form "file1.txt" instead of file1.txt ) but the origina files are still not deleted.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Also, I did rc = 20014 becasue that's the value that I get, and when I do rc = 0 I don't even get the message that the fileref will be truncated etc. and the original files are still there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0cm; margin-bottom: .0001pt; line-height: 15.0pt; orphans: auto; text-align: start; widows: 1; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2016 02:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264319#M269219</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-04-16T02:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264320#M269220</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;your code is basically the same as Reeza's, and I tried it and didn't get the files deleted. Please read my reply to Reeza if you like as it contains more description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2016 02:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264320#M269220</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-04-16T02:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264321#M269221</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The files are actually external files. Please read my reply to Reeza if you like because it contains more description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2016 02:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264321#M269221</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-04-16T02:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264487#M269222</link>
      <description>&lt;P&gt;You need to set the_name to a string that is a valid SAS name for a file reference (up to 8 characters, can only contain a-z, underline, and numbers, must start with underline or alphanumeric character). Easiest way to restrict the length is to do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length the_name $8;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the set statement, if the_name in dataset filelist is defined too long.&lt;/P&gt;
&lt;P&gt;This is what the message is complaining about.&lt;/P&gt;
&lt;P&gt;And checking for rc = 20014 is bogus because any rc other that zero from the filename function means that this function failed and the file reference for the_name does not exist; therefore no further operations on this nonexistent file reference are possible.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Apr 2016 07:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264487#M269222</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-18T07:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264983#M269223</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;I did include the length setting as you showed but still no result...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to delete manually a file with the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   the_name2="f1";
    rc=filename(the_name2,'C:\files\f1.txt');
    if rc = 0 and fexist(the_name2) then
       rc=fdelete(the_name2);
    rc=filename(the_name2);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it actually worked and the file was deleted!&lt;/P&gt;
&lt;P&gt;So for some reason the code doesn't want to work when the fileref and physical-filename are not manually written but are referenced by the column variable where they reside.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 02:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/264983#M269223</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2016-04-20T02:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically deleting external files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/265466#M269224</link>
      <description>&lt;P&gt;If you don'the have a variable the_name2 in your dataset, then the filename function tries to use an empty string as a fileref, and that will fail.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Apr 2016 16:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-deleting-external-files/m-p/265466#M269224</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-21T16:31:57Z</dc:date>
    </item>
  </channel>
</rss>

