<?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: SAS deleting file with dynamic file name in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793130#M81505</link>
    <description>What i mean is when I use my delete macro with the full path, the file deletes successfully &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 28 Jan 2022 14:09:10 GMT</pubDate>
    <dc:creator>Citrine10</dc:creator>
    <dc:date>2022-01-28T14:09:10Z</dc:date>
    <item>
      <title>SAS deleting file with dynamic file name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793115#M81503</link>
      <description>&lt;P&gt;Hi I am trying to delete a file by passing the filename in a variable. When using my delete macro the file deletes if I put the name there however when using my variable it doesnt work&lt;/P&gt;
&lt;PRE&gt;%include "C:/list.sas";
/*file paths*/
%let path_in= C:/FileCheck;
/*List of files*/
%list_files("C:/FileCheck",txt)

proc sql;
create table filecount  as
select name as filename
from tables (obs = 1);
quit;

%macro check(file);
%if %sysfunc(fileexist(&amp;amp;file)) ge 1 %then %do;
   %let rc=%sysfunc(filename(temp,&amp;amp;file));
   %let rc=%sysfunc(fdelete(&amp;amp;temp));
%end; 
%else %put The file &amp;amp;file does not exist;
%mend check; 


data tsave;
length y fname $200;
do i = 1 to 3;
  y = cats("C:/","&amp;amp;filename");
  fname = y;
  output;
  file dummy filevar=y;
  %check('&amp;amp;y')
end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jan 2022 12:29:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793115#M81503</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-01-28T12:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS deleting file with dynamic file name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793125#M81504</link>
      <description>&lt;P&gt;Can you elaborate a bit about "&lt;SPAN&gt;if I put the name there".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, if you could post any logs or anything can help us understand what happens in both scenarios.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 13:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793125#M81504</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-01-28T13:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS deleting file with dynamic file name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793130#M81505</link>
      <description>What i mean is when I use my delete macro with the full path, the file deletes successfully &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 28 Jan 2022 14:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793130#M81505</guid>
      <dc:creator>Citrine10</dc:creator>
      <dc:date>2022-01-28T14:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS deleting file with dynamic file name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793155#M81506</link>
      <description>&lt;P&gt;You are trying to use data from the DATA step (PDV) to generate macro calls.&amp;nbsp; For that, look into examples of people using CALL EXECUTE to generate macro calls.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As written, the code can't work because the macro %check executes before the data step with the DO loop has even finished compiling.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry I don't have time to give you a working example, I'm sure someone else will likely write a CALL EXECUTE solution for you.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 15:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793155#M81506</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-01-28T15:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS deleting file with dynamic file name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793164#M81507</link>
      <description>&lt;P&gt;Not macro needed. Please note that the key part of your "macro" is this&lt;/P&gt;
&lt;PRE&gt;fileexist(&amp;amp;file)&lt;/PRE&gt;
&lt;P&gt;FILEEXIST is a data step function. Which is why the %sysfunc is needed to execute it in a macro. As is FDELETE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Place the names in a data set and just use the Fileexist and Fdelete in data step code with the variable name holding the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It doesn't help that you 1) pass the value in the macro in quotes and 2) the quotes are single quotes preventing resolution of the macro variable which would 3) make the quote part of the value which would not be needed/wanted in the macro itself.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jan 2022 16:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793164#M81507</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-28T16:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS deleting file with dynamic file name</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793172#M81509</link>
      <description>&lt;P&gt;So let's assume that your first macro will create a dataset named TABLES with a variable named NAME hat has the name of a file without the path to the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then use a simple data step to use that dataset.&amp;nbsp; Add back the path so that you can then delete the files.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tsave;
  set tables;
  length fullname $256 fileref $8 ;
  fullname = catx('/',"c:\FileCheck",name);
  if fileexist(fullname) then do;
    rc=filename(fileref,fullname);
    if rc then put 'WARNING: Unable to create fileref for ' fullname= ;
    else do;
      rc=fdelete(fileref);
      if rc then put 'ERROR: Unable to delete ' fullname= ;
    end;
  end;
  else put 'WARNING: Unable to find ' fullname=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jan 2022 17:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-deleting-file-with-dynamic-file-name/m-p/793172#M81509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-28T17:57:17Z</dc:date>
    </item>
  </channel>
</rss>

