<?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: Linux: How do I FDELETE a file whose name contains square brackets [] in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970998#M377225</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300781"&gt;@RichardAD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I won't help you with a solution, unfortunately, but I have some more observations.&lt;/P&gt;
&lt;P&gt;1) It looks like it it's not only FDELETE() have problems with [].&lt;/P&gt;
&lt;P&gt;My idea was "let's try rename and the delete", so I did a small test for RENAME() with 6 different approaches, but it returned the same error, log below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 1          %put %sysfunc(rename(&amp;amp;testpath./ABC_\[123\]_DEF.txt, &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 2          %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 3          
 4          %put %sysfunc(rename("&amp;amp;testpath./ABC_[123]_DEF.txt", &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 5          %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 6          
 7          %put %sysfunc(rename('&amp;amp;testpath./ABC_[123]_DEF.txt', &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 8          %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 9          
 10         %put %sysfunc(rename(%str(&amp;amp;testpath./ABC_\[123\]_DEF.txt), &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 11         %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 12         
 13         %put %sysfunc(rename("&amp;amp;testpath./ABC_\[123\]_DEF.txt", &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 14         %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 15         
 16         %put %sysfunc(rename('&amp;amp;testpath./ABC_\[123\]_DEF.txt', &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 17         %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Furthermore, when I tried delete "&lt;CODE class=" language-sas"&gt;ABC_[123]_DEF.txt&lt;/CODE&gt;" in SAS Studio I also got an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Another "fun fact" is that when I created a directory with [], Linux tree command on OS level shows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;.
├── ABC_[123]_DEF.txt
├── DEF_[123]_DEF.txt
├── GHI_[123]_DEF.txt
└── test[123]
    ├── test[123]next.txt
    └── test.txt

1 directory, 5 files
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but SAS Studio does not see that sub-directory at all:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1752760884343.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/108426i54F568B96B81E070/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1752760884343.png" alt="yabwon_0-1752760884343.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;Last 2 things. If you happen to have XCMD on, maybe you could use filename PIPE to run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rm '/path/to/file/ABC_[123]_DEF.txt';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;on the OS level, with filename surrounded by quotes.&lt;/P&gt;
&lt;P&gt;Or, in the &lt;A href="https://github.com/SASPAC/baseplus" target="_self"&gt;BasePlus&lt;/A&gt; package there is the &lt;A href="https://github.com/SASPAC/baseplus/blob/main/baseplus.md#bppipe-macro-" target="_self"&gt;%bpPIPE()&lt;/A&gt; macro that may be useful:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%bpPIPE(rm "&amp;amp;testpath./ABC_[123]_DEF.txt")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Thu, 17 Jul 2025 14:10:16 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2025-07-17T14:10:16Z</dc:date>
    <item>
      <title>Linux: How do I FDELETE a file whose name contains square brackets []</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970970#M377211</link>
      <description>&lt;P&gt;I am dealing with some files that need to be FDELETED after they are used.&amp;nbsp; However, I only get a log message:&lt;/P&gt;
&lt;P&gt;ERROR: Invalid physical name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've discovered I can used brackets in some scenarios by using backslash (\[)...\]) to apparently escape the [ which causes the above error.&lt;/P&gt;
&lt;P&gt;I recall reading some SAS documentation that [] in filename is used like a regex character class, but I can't find that doc again -- it might have been Viya related, but I am not using Viya.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let workpath = %sysfunc(pathname(WORK)) ;
%let testpath = &amp;amp;workpath/test ;

options dlcreatedir ;
libname testpath "&amp;amp;testpath" ;
options nodlcreatedir ;
&lt;BR /&gt;* Create a test file whose name contains brackets ;
&lt;BR /&gt;filename bracket "&amp;amp;testpath/ABC_\[123\]_DEF.txt" ;
ata _null_;
  file bracket;
  put 'Where do you want these shelves?';
run ;
&lt;BR /&gt;* Process the test file ;&lt;BR /&gt;
data _null_ ;
  infile bracket ;
  input; put _infile_;
run; 

* List the files in test folder and try to delete them with FDELETE ;

data _null_ ;
 length dref fref $8 fname $256 msg $200 ;
  rc = filename (dref, "&amp;amp;testpath") ;
  did = dopen(dref);  msg=sysmsg() ;
  do i = 1 to dnum(did) ;
    fname = dread(did, i) ;
    put 'NOTE: ' i fname ;
    rc = filename (fref, cats("&amp;amp;testpath",'/',fname)) ; msg = sysmsg() ; put 'NOTE: filename() ' rc= fname= / msg ;
    rc = FDELETE(fref) ;  msg = sysmsg() ; put 'NOTE: fdelete() ' rc= / msg ;
    if index(fname,'[') then do ;
      fname = transtrn(fname,'[','\[') ;  * try to escape the brackets ;
      fname = transtrn(fname,']','\]') ;
      rc = filename (fref, cats("&amp;amp;testpath",'/',fname)) ; msg = sysmsg() ; put 'NOTE: filename() ' rc= fname= / msg ;
      rc = FDELETE(fref) ;  msg = sysmsg() ; put 'NOTE: fdelete() ' rc= / msg ;
    end ;
    rc = filename (fref) ;
  end ;
run ;

* try delete the escaped filename referenced by bracket;

%put NOTE: FDELETE rc=%sysfunc(fdelete(bracket)) ;
%put %sysfunc(sysmsg()) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will log the ERROR: for each way I try to FDELETE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;225        %let workpath = %sysfunc(pathname(WORK)) ;
226        %let testpath = &amp;amp;workpath/test ;
227        
228        options dlcreatedir ;
229        libname testpath "&amp;amp;testpath" ;
NOTE: Libref TESTPATH was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: /saswork/sas_tmp/SAS_work##########/SAS_work##########/test
230        options nodlcreatedir ;
231        
232        filename bracket "&amp;amp;testpath/ABC_\[123\]_DEF.txt" ;
233        
234        data _null_;
235          file bracket;
236          put 'Where do you want these shelves?';
237        run ;

NOTE: The file BRACKET is:
      Filename=/saswork/sas_tmp/SAS_work##########/SAS_work##########/test/ABC_\[123\]_DEF.txt,
      Owner Name=########,Group Name=########,
      Access Permission=-rw-rw-rw-,
      Last Modified=17Jul2025:08:27:44

NOTE: 1 record was written to the file BRACKET.
      The minimum record length was 32.
      The maximum record length was 32.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

238        
239        data _null_ ;
240          infile bracket ;
241          input; put _infile_;
242        run;

NOTE: The infile BRACKET is:
      Filename=/saswork/sas_tmp/SAS_work##########/SAS_work##########/test/ABC_\[123\]_DEF.txt,
      Owner Name=########,Group Name=########,
      Access Permission=-rw-rw-rw-,
      Last Modified=17Jul2025:08:27:44,
      File Size (bytes)=33

Where do you want these shelves?
NOTE: 1 record was read from the infile BRACKET.
      The minimum record length was 32.
      The maximum record length was 32.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

243        
244        * List the files in test folder and try to delete them ;
245        
246        data _null_ ;
247         length dref fref $8 fname $256 msg $200 ;
248          rc = filename (dref, "&amp;amp;testpath") ;
249          did = dopen(dref);  msg=sysmsg() ;
250          do i = 1 to dnum(did) ;
251            fname = dread(did, i) ;
252            put 'NOTE: ' i fname ;
253            rc = filename (fref, cats("&amp;amp;testpath",'/',fname)) ; msg = sysmsg() ; put 'NOTE: filename() ' rc= fname= / msg ;
254            rc = FDELETE(fref) ;  msg = sysmsg() ; put 'NOTE: fdelete() ' rc= / msg ;
255            if index(fname,'[') then do ;
256              fname = transtrn(fname,'[','\[') ;
257              fname = transtrn(fname,']','\]') ;
258              rc = filename (fref, cats("&amp;amp;testpath",'/',fname)) ; msg = sysmsg() ; put 'NOTE: filename() ' rc= fname= / msg ;
259              rc = FDELETE(fref) ;  msg = sysmsg() ; put 'NOTE: fdelete() ' rc= / msg ;
260            end ;
261            rc = filename (fref) ;
262          end ;
263        run ;

NOTE: 1 ABC_[123]_DEF.txt
NOTE: filename() rc=0 fname=ABC_[123]_DEF.txt

NOTE: fdelete() rc=20017
ERROR: Invalid physical name.
NOTE: filename() rc=0 fname=ABC_\[123\]_DEF.txt

NOTE: fdelete() rc=20017
ERROR: Invalid physical name.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

264        
265        * try delete the escaped filename referenced by bracket;
266        
267        %put NOTE: macro FDELETE rc=%sysfunc(fdelete(bracket)) ;
NOTE: macro FDELETE rc=20017
268        %put %sysfunc(sysmsg()) ;
ERROR: Invalid physical name.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Jul 2025 08:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970970#M377211</guid>
      <dc:creator>RichardAD</dc:creator>
      <dc:date>2025-07-17T08:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Linux: How do I FDELETE a file whose name contains square brackets []</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970988#M377217</link>
      <description>&lt;P&gt;I would raise that as an issue with SAS support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Square brackets should not cause any trouble in SAS code and I am pretty sure they did not in the past.&amp;nbsp; But at the very least FDELETE() should handle the same way as normal writing and reading operations do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have definitely had the opposite problem in the past.&amp;nbsp; SAS would allow you to make filenames that are difficult to work with from Unix prompt.&amp;nbsp; Names with spaces or * in them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jul 2025 13:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970988#M377217</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-17T13:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Linux: How do I FDELETE a file whose name contains square brackets []</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970998#M377225</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/300781"&gt;@RichardAD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I won't help you with a solution, unfortunately, but I have some more observations.&lt;/P&gt;
&lt;P&gt;1) It looks like it it's not only FDELETE() have problems with [].&lt;/P&gt;
&lt;P&gt;My idea was "let's try rename and the delete", so I did a small test for RENAME() with 6 different approaches, but it returned the same error, log below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 1          %put %sysfunc(rename(&amp;amp;testpath./ABC_\[123\]_DEF.txt, &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 2          %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 3          
 4          %put %sysfunc(rename("&amp;amp;testpath./ABC_[123]_DEF.txt", &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 5          %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 6          
 7          %put %sysfunc(rename('&amp;amp;testpath./ABC_[123]_DEF.txt', &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 8          %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 9          
 10         %put %sysfunc(rename(%str(&amp;amp;testpath./ABC_\[123\]_DEF.txt), &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 11         %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 12         
 13         %put %sysfunc(rename("&amp;amp;testpath./ABC_\[123\]_DEF.txt", &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 14         %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.
 15         
 16         %put %sysfunc(rename('&amp;amp;testpath./ABC_\[123\]_DEF.txt', &amp;amp;testpath./ABC_123_DEF.txt, file));
 1
 17         %put %sysfunc(sysmsg()) ;
 ERROR: Invalid physical name.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Furthermore, when I tried delete "&lt;CODE class=" language-sas"&gt;ABC_[123]_DEF.txt&lt;/CODE&gt;" in SAS Studio I also got an error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Another "fun fact" is that when I created a directory with [], Linux tree command on OS level shows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;.
├── ABC_[123]_DEF.txt
├── DEF_[123]_DEF.txt
├── GHI_[123]_DEF.txt
└── test[123]
    ├── test[123]next.txt
    └── test.txt

1 directory, 5 files
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but SAS Studio does not see that sub-directory at all:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1752760884343.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/108426i54F568B96B81E070/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1752760884343.png" alt="yabwon_0-1752760884343.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;Last 2 things. If you happen to have XCMD on, maybe you could use filename PIPE to run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rm '/path/to/file/ABC_[123]_DEF.txt';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;on the OS level, with filename surrounded by quotes.&lt;/P&gt;
&lt;P&gt;Or, in the &lt;A href="https://github.com/SASPAC/baseplus" target="_self"&gt;BasePlus&lt;/A&gt; package there is the &lt;A href="https://github.com/SASPAC/baseplus/blob/main/baseplus.md#bppipe-macro-" target="_self"&gt;%bpPIPE()&lt;/A&gt; macro that may be useful:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%bpPIPE(rm "&amp;amp;testpath./ABC_[123]_DEF.txt")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jul 2025 14:10:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/970998#M377225</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-07-17T14:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: Linux: How do I FDELETE a file whose name contains square brackets []</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/971013#M377237</link>
      <description>&lt;P&gt;If you do have XCMD option enabled you can use the Unix command rm to delete the file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  cmd=catx(' ','rm',pathname('bracket'));
  infile dummy pipe filevar=cmd;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&amp;nbsp; You might need use \rm instead of rm as the command.&amp;nbsp; This will force it use the rm command directly instead of any alias that might have been defined.&amp;nbsp; to avoid complication from Unix shops that have defined aliases for rm to force it to prompt before removing a file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jul 2025 15:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Linux-How-do-I-FDELETE-a-file-whose-name-contains-square/m-p/971013#M377237</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-17T15:11:41Z</dc:date>
    </item>
  </channel>
</rss>

