<?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 with different names between SAS server folders without using xcopy in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799558#M314419</link>
    <description>&lt;P&gt;Read the filenames from the directory, and use FCOPY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length
  fref_in fref_out dref $8
  fname $200
;
rc = filename(dref,"/opt/sas/data/xxx/xx/xx/xxx/FinalFolder");
did = dopen(dref);
if did /* if did is not 0, indicating the dopen worked */
then do;
  do i = 1 to dnum(did);
    fname = dread(did,i);
    if /* insert filter condition for fname here */
    then do;
    rc = filename(fref_in,"/opt/sas/data/xxx/xx/xx/xxx/FinalFolder/" !! fname, "recfm=n");
    rc = filename(fref_out,"/opt/sas/data/xxx/xx/xx/xxx/BridgeFolder/" !! fname, "recfm=n");
    rc = fcopy(fref_in,fref_out);
    rc = filename(fref_in);
    rc = filename(fref_out);
  end;
  rc = dclose(did);
end;
rc = filename(dref);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Mar 2022 12:49:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-03-02T12:49:06Z</dc:date>
    <item>
      <title>Move multiple files with different names between SAS server folders without using xcopy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799548#M314416</link>
      <description>&lt;P&gt;Hello everyone, I'm new to programming in SAS and I'm trying to create a macro that moves the 160 .xlsx files that are generated in one folder, to another, within the SAS server. The names of the files are different and it cannot be use the wildcard "*" to name all the files, that's why I had thought of a macro with macrovariables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I intend to do is the following, The file names always start with "XDF_" followed by a number (for example: 0001475) this number is a field called cod_SAP from another table, then the date would go (I have no problem with this ) then it would go again "_XDF_M2_"month in number format, type 202202".xlsx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is, if we pass this to macrovariables it would be something like this:&lt;/P&gt;
&lt;P&gt;XDF_&amp;amp;column._&amp;amp;date._XDF_M2_&amp;amp;month..xlsx&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;And a file would be for example:&lt;BR /&gt;XDF_0001475_20220302_XDF_M2_202203.xlsx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They will all have the same value in the date and month macrovariable, what will change will be the codes. There are 160 different codes so I have 160 .xlsx files that I want to move.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I have been testing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data tabletest;
	set origintable;
	Rank + 1;
	if first.test then Rank = 1;
run;
PROC SQL;
CREATE TABLE TEST1 as
SELECT DISTINCT cod_SAP, Rank
FROM TABLETEST;
QUIT;
data _null_;
	set TEST1;
	call symput ('codes',_n_);
run;
%macro testmove;
%global month;
%let month = 202112;
%global date;
%let date= 20220302;

%do i=1 %to &amp;amp;codes; 

data _null_;
	set tabletest(where=(rank=&amp;amp;i.));
	call symput ('column',compress(cod_SAP));
run;

filename in "/opt/sas/data/xxx/xx/xx/xxx/FinalFolder/XDF_&amp;amp;column._&amp;amp;date._XDF_M2_&amp;amp;month..xlsx";
filename out "/opt/sas/data/xx/xx/xx/xx/BridgeFolder/XDF_&amp;amp;column._&amp;amp;date._XDF_M2_&amp;amp;month..xlsx";

            * copy the file byte-for-byte;
            data _null_;
             length filein 8 fileid 8;
             filein = fopen('in','I',1,'B');
             fileid = fopen('out','O',1,'B');
             rec = '20'x;
             do while(fread(filein)=0);
                rc = fget(filein,rec,1);
                rc = fput(fileid, rec);
                rc =fwrite(fileid);
             end;
             rc = fclose(filein);
             rc = fclose(fileid);
            run;

            filename in clear;
            filename out clear;

%end;
%mend testmove;
%testmove;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What happens with this code is that it simply copies 5 files and sometimes it does it when they are empty, it only copies the empty excel and with the name that is in the source folder, could someone tell me where the error would be? or any other alternative to try to move 160 excel files with different names to another folder automatically?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't use xcopy, I have to do it with the noxcmd option enabled&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much in advance&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 12:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799548#M314416</guid>
      <dc:creator>Abelp9</dc:creator>
      <dc:date>2022-03-02T12:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files with different names between SAS server folders without using xcopy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799558#M314419</link>
      <description>&lt;P&gt;Read the filenames from the directory, and use FCOPY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length
  fref_in fref_out dref $8
  fname $200
;
rc = filename(dref,"/opt/sas/data/xxx/xx/xx/xxx/FinalFolder");
did = dopen(dref);
if did /* if did is not 0, indicating the dopen worked */
then do;
  do i = 1 to dnum(did);
    fname = dread(did,i);
    if /* insert filter condition for fname here */
    then do;
    rc = filename(fref_in,"/opt/sas/data/xxx/xx/xx/xxx/FinalFolder/" !! fname, "recfm=n");
    rc = filename(fref_out,"/opt/sas/data/xxx/xx/xx/xxx/BridgeFolder/" !! fname, "recfm=n");
    rc = fcopy(fref_in,fref_out);
    rc = filename(fref_in);
    rc = filename(fref_out);
  end;
  rc = dclose(did);
end;
rc = filename(dref);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Mar 2022 12:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799558#M314419</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-02T12:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Move multiple files with different names between SAS server folders without using xcopy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799567#M314422</link>
      <description>&lt;P&gt;I have a pre-canned macro for this named &lt;STRONG&gt;filemove&lt;/STRONG&gt;. You can get it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Grab a copy of the filemove macro */
%let thisMacro=filemove;
filename mCode "c:\temp\%qlowcase(&amp;amp;thisMacro).sas";
proc http url="https://raw.githubusercontent.com/SASJedi/sas-macros/master/%qlowcase(&amp;amp;thisMacro).sas"
          out=mcode;
run;

%include mcode /source2;
filename mcode;
%&amp;amp;thismacro(?)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro call with the question mark writes documentation to the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;NOTE: FILEMOVE documentation:
      Purpose: Move a file from one directory to another
      Syntax: %FILEMOVE(fileName, sourcePath,targetPath&amp;lt;,newFileName&amp;gt;)
      fileName:    Name of the file to be copied
      sourcePath:  path where the source file is located
      targetPath:  path to which the file will be moved
      newFileName: OPTIONAL: New name for the copied file

      Examples:
      %FILEMOVE(abc.txt,c:\temp\source,c:\temp\target)
      %FILEMOVE(old.csv,c:\temp\source,c:\temp\target,new.csv)

      Use ? to print documentation to the SAS log.
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;To copy your file from one directory to another, something like this would do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%fileMove(XDF_&amp;amp;column._&amp;amp;date._XDF_M2_&amp;amp;month..xlsx
         ,/opt/sas/data/xxx/xx/xx/xxx/FinalFolder
         ,/opt/sas/data/xx/xx/xx/xx/BridgeFolder);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 13:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-with-different-names-between-SAS-server/m-p/799567#M314422</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-03-02T13:48:12Z</dc:date>
    </item>
  </channel>
</rss>

