[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: This copy doesnt seem to work
From:       Roger DeAngelis <rogerjdeangelis () GMAIL ! COM>
Date:       2019-10-31 19:06:01
Message-ID: CAOUdXL8CY6G12-KxJQbbJvG5JU9h6U9Qc5RuoWgUvN5F_ffMXg () mail ! gmail ! com
[Download RAW message or body]

I prefer to use operating system commads, but if you don't have an
operating system you cam

try

I don't think you can dopen  supports the 'b' argument like fopen does.

Also you can use 'recfm=n' or


github
https://tinyurl.com/y6qjceow
https://github.com/rogerjdeangelis/utl-copying-binary-files-from-one-directory-to-another-using-a-data-_null_


SAS Forum
https://tinyurl.com/yyekhuxj
https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593272

Unix cp
or
windows
robocopy
xcopy

github
https://tinyurl.com/y4u776gf
https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&docsetVersion=9.4&locale=en


Example 2: Copying a Binary File
This example copies a binary file from one directory to another. Setting the
MSGLEVEL= system option to I causes informational messages from FCOPY to be
written to the log.
   /* Set MSGLEVEL to I to write messages from FCOPY to the log. */
options msglevel=i;

filename src 'raises.xlsx' recfm=n;
filename dest 'raises-2012.xlsx' recfm=n;

   /* Create an example file to copy. */
data _null_;
   file src;
   do i=1, 2105, 300312, 400501;
     put i:words256.;
   end;
run;

data _null_;
   length msg $ 384;
   rc=fcopy('src', 'dest');
   if rc=0 then
      put 'Copied SRC to DEST.';
   else do;
      msg=sysmsg();
      put rc= msg=;
   end;
run;



On Thu, Oct 31, 2019 at 2:32 PM Jeff Kroll <jmkroll@gmail.com> wrote:

> Ive created the code below to move some files from one folder to another
> after the files have been processed.  It seems to work for TXT files but no
> so much for XLSX.  Once the file is moved Excel no longer recognizes it as
> a valid Excel file.  Does anything stand out as wrong to anyone?  I know
> there are other ways to do this with DOS commands but I cant use those for
> this process.
> 
> %macro copy_files(source,destination,type);
> 
> /* this macro will copy all files of the same type from one folder to
> another */
> 
> data _null_;
> rc=filename("temp","&source");
> did=dopen("temp");
> length filename $ 40;
> if did > 0
> then do;
> num = dnum(did);
> do i = 1 to num;
> filename = dread(did,i);
> if index(filename,"&type")
> then do;
> rc=filename("src","&source\"!!strip(filename));
> outfile = "&destination\"!!strip(filename);
> rc=filename("dest",outfile);
> rc=fcopy('src','dest'); msg=sysmsg();
> rc=filename("dest");
> rc=filename("src");
> end;
> end;
> end;
> rc=filename("temp");
> run;
> 
> %mend;
> 
> %copy_files(&fileloc\self service\excel to pipe,&fileloc\self
> service\excel to pipe\archive,xlsx);
> 


[Attachment #3 (text/html)]

<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">I \
prefer to use operating system commads, but if you don&#39;t have an operating system \
you cam<br><br>try<br><br>I don&#39;t think you can dopen   supports the &#39;b&#39; \
argument like fopen does.<br><br>Also you can use &#39;recfm=n&#39; \
or<br><br><br>github<br><a \
href="https://tinyurl.com/y6qjceow">https://tinyurl.com/y6qjceow</a><br><a \
href="https://github.com/rogerjdeangelis/utl-copying-binary-files-from-one-directory-t \
o-another-using-a-data-_null_">https://github.com/rogerjdeangelis/utl-copying-binary-files-from-one-directory-to-another-using-a-data-_null_</a><br><br>SAS \
Forum<br><a href="https://tinyurl.com/yyekhuxj">https://tinyurl.com/yyekhuxj</a><br><a \
href="https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/59 \
3272">https://communities.sas.com/t5/SAS-Programming/Move-multiple-files-in-SAS/m-p/593272</a><br><br>Unix \
cp<br>or<br>windows<br>robocopy<br>xcopy<br><br>github<br><a \
href="https://tinyurl.com/y4u776gf">https://tinyurl.com/y4u776gf</a><br><a \
href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;docsetTarget=n10dz22b \
5ixohin1vwzilweetek0.htm&amp;docsetVersion=9.4&amp;locale=en">https://documentation.sa \
s.com/?docsetId=lefunctionsref&amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;docsetVersion=9.4&amp;locale=en</a><br><br>Example \
2: Copying a Binary File<br>This example copies a binary file from one directory to \
another. Setting the<br>MSGLEVEL= system option to I causes informational messages \
from FCOPY to be written to the log.<br>     /* Set MSGLEVEL to I to write messages \
from FCOPY to the log. */<br>options msglevel=i;<br><br>filename src \
&#39;raises.xlsx&#39; recfm=n;<br>filename dest &#39;raises-2012.xlsx&#39; \
recfm=n;<br><br>     /* Create an example file to copy. */<br>data _null_;<br>     \
file src;<br>     do i=1, 2105, 300312, 400501;<br>        put i:words256.;<br>     \
end;<br>run;<br><br>data _null_;<br>     length msg $ 384;<br>     \
rc=fcopy(&#39;src&#39;, &#39;dest&#39;);<br>     if rc=0 then<br>         put \
&#39;Copied SRC to DEST.&#39;;<br>     else do;<br>         msg=sysmsg();<br>         \
put rc= msg=;<br>     end;<br>run;<br><br><br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Oct 31, 2019 at 2:32 PM \
Jeff Kroll &lt;<a href="mailto:jmkroll@gmail.com">jmkroll@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Ive created the code \
below to move some files from one folder to another after the files have been \
processed.   It seems to work for TXT files but no so much for XLSX.   Once the file \
is moved Excel no longer recognizes it as a valid Excel file.   Does anything stand \
out as wrong to anyone?   I know there are other ways to do this with DOS commands \
but I cant use those for this process.<br> <br>
%macro copy_files(source,destination,type);<br>
<br>
/* this macro will copy all files of the same type from one folder to another */<br>
<br>
data _null_;<br>
  rc=filename(&quot;temp&quot;,&quot;&amp;source&quot;);<br>
  did=dopen(&quot;temp&quot;);<br>
  length filename $ 40;<br>
  if did &gt; 0<br>
  then do;<br>
           num = dnum(did);<br>
                 do i = 1 to num;<br>
                    filename = dread(did,i);<br>
                          if index(filename,&quot;&amp;type&quot;) <br>
              then do;<br>
                                   \
                rc=filename(&quot;src&quot;,&quot;&amp;source\&quot;!!strip(filename));<br>
                
                                   outfile = \
                &quot;&amp;destination\&quot;!!strip(filename);<br>
                                   rc=filename(&quot;dest&quot;,outfile);<br>
                                         rc=fcopy(&#39;src&#39;,&#39;dest&#39;); \
                msg=sysmsg();<br>
                                         rc=filename(&quot;dest&quot;);<br>
                                         rc=filename(&quot;src&quot;);<br>
                                       end;<br>
                 end;<br>
               end;<br>
  rc=filename(&quot;temp&quot;);<br>
run;<br>
<br>
%mend;<br>
<br>
%copy_files(&amp;fileloc\self service\excel to pipe,&amp;fileloc\self service\excel \
to pipe\archive,xlsx);<br> </blockquote></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic