<?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: Move multiple files in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593304#M170252</link>
    <description>&lt;P&gt;I do not think you need a macro for that, e.g. (code not tested):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indir=directory1;
%let outdir=directory2;
data _null_;
    infile cards;
    input filetomove $50;
    rc = filename("_IN_", "&amp;amp;indir/"!!filetomove);
    if rc = 0 and fexist("_IN_") then
      do;
        rc = filename('_OUT_',"&amp;amp;outdir/"!!filetomove);
        rc = fcopy("_IN_", '_OUT_');      
        if rc=0 then
          rc = fdelete("_IN_"); &lt;BR /&gt;        else
          stop;
        rc = filename('_OUT_');
      end;
  rc = filename("_IN_");  
cards;
file_1
file_2
file_5
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put in a check, so that if FCOPY returned an error or warning (which you will get with e.g. a truncation), the process will abort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if your files are actually named with number suffixes, and you know how many (or the maximum number) to move:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indir=directory1;
%let outdir=directory2;
%let fileprefix=file_;
%let nooffiles=33;
data _null_;
  do _N_=1 to &amp;amp;nooffiles;
    rc = filename("_IN_", cats("&amp;amp;indir/&amp;amp;fileprefix",_N_));
    if rc = 0 and fexist("_IN_") then do;
        rc = filename('_OUT_',cats("&amp;amp;outdir/&amp;amp;fileprefix",_N_));
        rc = fcopy("_IN_", '_OUT_');      
        if rc = 0 then
          rc = fdelete("_IN_"); 
        else
           stop;
         rc = filename('_OUT_');
      end;
    rc = filename("_IN_");  &lt;BR /&gt;  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Oct 2019 11:22:10 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2019-10-02T11:22:10Z</dc:date>
    <item>
      <title>Move multiple files in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593272#M170241</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to move a set of multiple files file_1, …., file_k with a data null step, so I am applying the following SAS code to achieve this task:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro skip(trans_rc,
in,
out,
);

%put **&amp;amp;=trans_rc.**;
%if (&amp;amp;trans_rc. ne 0) %then %do;
  data _null_;
    rc = filename("_IN_", &amp;amp;in.);
    if rc = 0 and fexist("_IN_") then
      do;
        rc = filename('_OUT_',&amp;amp;out.);
        rc = fcopy("_IN_", '_OUT_');      
        rc = fdelete("_IN_"); rc = filename('_OUT_');
      end;
  rc = filename("_IN_");  run;
%end;
%mend skip;
%skip(&amp;amp;trans_rc.
,'directory1/file_1'
,'directory2/file_1'
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In this sense, I have been trying to generalize this code to move all the files file_1, …, file_k (i.e. not only file_1), but I have not been successful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 09:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593272#M170241</guid>
      <dc:creator>George_SAS</dc:creator>
      <dc:date>2019-10-02T09:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593278#M170243</link>
      <description>&lt;P&gt;I know that a simple possibility is to apply multiple times the skip function, for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%skip(&amp;amp;trans_rc.
,'directory1/file_1'
,'directory2/file_1'
)

%skip(&amp;amp;trans_rc.
,'directory1/file_k'
,'directory2/file_k'
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In any case, I am asking for a more compact solution to move in a simple step the entire set of files. For example, one could apply the following simple code by the use of wildcards in Unix:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;mv /directory1/file* /directory2&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I can't use this statement with the sysexec function in SAS, for an issue related to a lack of permissions. That's why I am using the data null step in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 10:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593278#M170243</guid>
      <dc:creator>George_SAS</dc:creator>
      <dc:date>2019-10-02T10:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593304#M170252</link>
      <description>&lt;P&gt;I do not think you need a macro for that, e.g. (code not tested):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indir=directory1;
%let outdir=directory2;
data _null_;
    infile cards;
    input filetomove $50;
    rc = filename("_IN_", "&amp;amp;indir/"!!filetomove);
    if rc = 0 and fexist("_IN_") then
      do;
        rc = filename('_OUT_',"&amp;amp;outdir/"!!filetomove);
        rc = fcopy("_IN_", '_OUT_');      
        if rc=0 then
          rc = fdelete("_IN_"); &lt;BR /&gt;        else
          stop;
        rc = filename('_OUT_');
      end;
  rc = filename("_IN_");  
cards;
file_1
file_2
file_5
;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put in a check, so that if FCOPY returned an error or warning (which you will get with e.g. a truncation), the process will abort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if your files are actually named with number suffixes, and you know how many (or the maximum number) to move:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indir=directory1;
%let outdir=directory2;
%let fileprefix=file_;
%let nooffiles=33;
data _null_;
  do _N_=1 to &amp;amp;nooffiles;
    rc = filename("_IN_", cats("&amp;amp;indir/&amp;amp;fileprefix",_N_));
    if rc = 0 and fexist("_IN_") then do;
        rc = filename('_OUT_',cats("&amp;amp;outdir/&amp;amp;fileprefix",_N_));
        rc = fcopy("_IN_", '_OUT_');      
        if rc = 0 then
          rc = fdelete("_IN_"); 
        else
           stop;
         rc = filename('_OUT_');
      end;
    rc = filename("_IN_");  &lt;BR /&gt;  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2019 11:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593304#M170252</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-02T11:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593310#M170253</link>
      <description>&lt;P&gt;As present above, in this case&amp;nbsp;the copy of the external files is executed only if the variable "trans_rc" is not equal to 0. In this sense, I can't see in your code this possibility.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On the other hand, such a condition can be appropriately implemented with the previous macro, but I just need to generalize it in a more compact form to copy a set of multiple files.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 11:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593310#M170253</guid>
      <dc:creator>George_SAS</dc:creator>
      <dc:date>2019-10-02T11:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593338#M170255</link>
      <description>&lt;P&gt;You are right. But you can just put in a line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;trans_rc then stop;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;in the beginning of the datastep&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 12:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593338#M170255</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-10-02T12:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593358#M170267</link>
      <description>&lt;P&gt;I have noted that your line &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;trans_rc &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; stop&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; in the beginning of the datastep Works completely fine&amp;nbsp;for the case where trans_rc is not&amp;nbsp;equal to 0, as mentioned above. However, what happens if I want to apply the copy for the case where trans_rc is equal to 0? I have tried to put the line &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;trans_rc eq 0 then do: in your example but it does not copy the set of files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indir=directory1;
%let outdir=directory2;
%let fileprefix=file_;
%let nooffiles=33;
data _null_;
if &amp;amp;trans_rc eq 0 then do;
  do _N_=1 to &amp;amp;nooffiles;
    rc = filename("_IN_", cats("&amp;amp;indir/&amp;amp;fileprefix",_N_));
    if rc = 0 and fexist("_IN_") then do;
        rc = filename('_OUT_',cats("&amp;amp;outdir/&amp;amp;fileprefix",_N_));
        rc = fcopy("_IN_", '_OUT_');      
        if rc = 0 then
          rc = fdelete("_IN_"); 
        else
           stop;
         rc = filename('_OUT_');
      end;
    rc = filename("_IN_");    end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How can I&amp;nbsp;implement your code with&amp;nbsp;the if condition in terms of the specific value of trans_rc?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much again.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 13:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593358#M170267</guid>
      <dc:creator>George_SAS</dc:creator>
      <dc:date>2019-10-02T13:26:10Z</dc:date>
    </item>
  </channel>
</rss>

