<?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: Delete excel files from drive using SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-excel-files-from-drive-using-SAS/m-p/562592#M157614</link>
    <description>&lt;P&gt;If you have the name and path of the files then basically you use your existing SAS data set and modify&lt;/P&gt;
&lt;PRE&gt; rcref = filename('fref',catx('\',"&amp;amp;path.",fname));

 rcdel = fdelete('fref');&lt;/PRE&gt;
&lt;P&gt;to use the information in your data set to create the file name replacing the information in&lt;/P&gt;
&lt;P&gt;,"&amp;amp;path.",fname with the variables you have in your data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the code in the example from the&lt;/P&gt;
&lt;P&gt;did &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;dopen&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'filrf'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;to &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;fname &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;dread&lt;/SPAN&gt;(did,memcount);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;basically only is getting the names of files in the folder provided by the &amp;amp;path variable. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;So since you know what you want you don't need to search and go directly to the delete portion.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;If you are implying that you do not know the folder they should be in, then that is another issue entirely.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;It almost always helps to provide examples of your existing data so we don't have to guess as to what you might have.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 30 May 2019 15:19:52 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-30T15:19:52Z</dc:date>
    <item>
      <title>Delete excel files from drive using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-excel-files-from-drive-using-SAS/m-p/562589#M157613</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having problems trying to edit some code to delete specific excel files from a folder. I have a list of filenames and extensions in a&amp;nbsp;table already in SAS, so I just need the code to find those filenames and delete them. I found the below code online and it does delete all the .xlsx .xls&amp;nbsp;files in a folder. However I don't want to delete all files, only the ones within my dataset work.FileN.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=D:\temp;

filename filrf "&amp;amp;path.";

data test;


/*Set work.FileN; This holds all the filenames and extensions e.g P1.xlsx, P2.xlsx etc.. in column called filename */

did = dopen('filrf');


memcount = dnum(did);

do while (memcount&amp;gt;0);

 

fname = dread(did,memcount);

if

scan(lowcase(fname),2,'.') in ('xls','xlsx') 



then do;

 rcref = filename('fref',catx('\',"&amp;amp;path.",fname));

 rcdel = fdelete('fref');

end;

 memcount+-1;

end;

stop;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 15:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-excel-files-from-drive-using-SAS/m-p/562589#M157613</guid>
      <dc:creator>PazM</dc:creator>
      <dc:date>2019-05-30T15:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Delete excel files from drive using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-excel-files-from-drive-using-SAS/m-p/562592#M157614</link>
      <description>&lt;P&gt;If you have the name and path of the files then basically you use your existing SAS data set and modify&lt;/P&gt;
&lt;PRE&gt; rcref = filename('fref',catx('\',"&amp;amp;path.",fname));

 rcdel = fdelete('fref');&lt;/PRE&gt;
&lt;P&gt;to use the information in your data set to create the file name replacing the information in&lt;/P&gt;
&lt;P&gt;,"&amp;amp;path.",fname with the variables you have in your data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the code in the example from the&lt;/P&gt;
&lt;P&gt;did &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;dopen&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'filrf'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;to &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;fname &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;dread&lt;/SPAN&gt;(did,memcount);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;basically only is getting the names of files in the folder provided by the &amp;amp;path variable. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;So since you know what you want you don't need to search and go directly to the delete portion.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;If you are implying that you do not know the folder they should be in, then that is another issue entirely.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;It almost always helps to provide examples of your existing data so we don't have to guess as to what you might have.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 15:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-excel-files-from-drive-using-SAS/m-p/562592#M157614</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-30T15:19:52Z</dc:date>
    </item>
  </channel>
</rss>

