<?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: What is the fastest and saves way to copy files without x command in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810722#M319726</link>
    <description>&lt;P&gt;As long as you follow the documentation, I see no risk of data corruption.&lt;/P&gt;
&lt;P&gt;Regarding the relative speed: try it out.&lt;/P&gt;
&lt;P&gt;And if speed is so important to you, use the command provided by the operating system.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Apr 2022 18:38:25 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-04-29T18:38:25Z</dc:date>
    <item>
      <title>What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810562#M319633</link>
      <description>&lt;P&gt;Hoi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to use the folowing method to copy .egp and .sas files from source folder (sas grid) to destination folder (sas grid).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this the fastest and the saves way to copy files (egp and sas) to destination folder without corrupting the source and destination files.&lt;/P&gt;
&lt;P&gt;Is this bullet proof, so when a developer opens the egp file when this macro is executing, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%macro copy_files(destdir=,totobs=,type=);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%if &amp;amp;totobs. &amp;gt; 0 %then %do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%do i = 1 %to &amp;amp;totobs.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;TempPath= "&amp;amp;&amp;amp;&amp;amp;copy_&amp;amp;type._&amp;amp;i.";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;InName = reverse(TempPath);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;InName = substr( InName, 1, index( InName, '/') -1 );&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;InName = left( reverse( InName ) );&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;call symputx( 'Inname', Inname ); &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%put %str(N)OTE: [ Copy from: &amp;amp;&amp;amp;&amp;amp;copy_&amp;amp;type._&amp;amp;i. ];&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%put %str(N)OTE: [ Copy to: &amp;amp;destdir/&amp;amp;&amp;amp;Inname. ];&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;filename insource "&amp;amp;&amp;amp;&amp;amp;KOPIE_&amp;amp;type._&amp;amp;i."; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;filename outsource "&amp;amp;doeldir/&amp;amp;&amp;amp;Inname."; &lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;/* Byte for byte copy file */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;length filein 8 fileid 8;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;filein = fopen('insource','I',1,'B');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;fileid = fopen('outsource','O',1,'B');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;rec = '20'x;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;do while(fread(filein)=0);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;rc = fget(filein,rec,1);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;rc = fput(fileid, rec);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;rc =fwrite(fileid);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;rc = fclose(filein);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;rc = fclose(fileid);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;filename insource clear;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;filename outsource clear;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%mend copy_files;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before i execute the macro, ik created a table with list of files in folders. The results of te table ar used to create variables that i passed to the macro. So assume that the work table exists with these rows as example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="756"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="80"&gt;enviroment&lt;/TD&gt;
&lt;TD width="172"&gt;dir&lt;/TD&gt;
&lt;TD width="93"&gt;sourcefile&lt;/TD&gt;
&lt;TD width="267"&gt;fullpath&lt;/TD&gt;
&lt;TD width="66"&gt;dirniveau&lt;/TD&gt;
&lt;TD width="78"&gt;label&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;O&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev&lt;/TD&gt;
&lt;TD&gt;project_a.egp&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev/project_a.egp&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;dev_source&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;O&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev&lt;/TD&gt;
&lt;TD&gt;project_b.egp&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev/project_b.egp&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;dev_source&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;O&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/prod&lt;/TD&gt;
&lt;TD&gt;project_a.sas&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev/project_a.sas&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;prod_source&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;O&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/prod&lt;/TD&gt;
&lt;TD&gt;project_c.egp&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev/project_c.egp&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;prod_source&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;O&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/prod&lt;/TD&gt;
&lt;TD&gt;project_c.sas&lt;/TD&gt;
&lt;TD&gt;/srv/SAS/data/source/dev/project_c.sas&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;prod_source&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%if (&amp;amp;TABLE_EXISTS eq 1) %then&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%do;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;proc sql noprint; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;select fullpath&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;into :COPY_SOURCEFILE_1 - :COPY_SOURCEFILE_999999&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;from WORK.FILELIST&lt;/FONT&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%let SOURCEFILEOBS = &amp;amp;SYSNOBS.; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;quit;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%put &amp;amp;SOURCEFILEOBS. files are found;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%put %str(NOTE: FILELIST existst and files are copied...);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%copy_files(destdir=/srv/destinationdir, totobs=&amp;amp;SOURCEFILEOBS, type=SOURCEFILE);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva" size="2" color="#0000FF"&gt;%end;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 09:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810562#M319633</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-04-29T09:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810576#M319642</link>
      <description>&lt;P&gt;Look at the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n10dz22b5ixohin1vwzilweetek0.htm" target="_blank" rel="noopener"&gt;FCOPY Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation contains an example for a binary copy.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 10:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810576#M319642</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-29T10:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810710#M319717</link>
      <description>Ok, but why is fcopy better?</description>
      <pubDate>Fri, 29 Apr 2022 18:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810710#M319717</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-04-29T18:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810713#M319720</link>
      <description>&lt;P&gt;First of all, it saves you a lot of time writing the code. Second, you can bet that SAS has spent a lot of work optimizing the function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 18:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810713#M319720</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-29T18:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810718#M319722</link>
      <description>ok but i am curious about the difference, why is fcopy better than byte for byte copy.&lt;BR /&gt;&lt;BR /&gt;is fcopy a method that often preffered to copy files? is it faster and are there possibilities that the source can be corrupted by using this procedure?</description>
      <pubDate>Fri, 29 Apr 2022 18:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810718#M319722</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-04-29T18:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810722#M319726</link>
      <description>&lt;P&gt;As long as you follow the documentation, I see no risk of data corruption.&lt;/P&gt;
&lt;P&gt;Regarding the relative speed: try it out.&lt;/P&gt;
&lt;P&gt;And if speed is so important to you, use the command provided by the operating system.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2022 18:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810722#M319726</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-29T18:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810728#M319731</link>
      <description>Ok i will try it out and compare the speed of both. &lt;BR /&gt;&lt;BR /&gt;Most important is that it doesnt corrupt the source and copied files. &lt;BR /&gt;&lt;BR /&gt;the reason why the speed is important is that o copie hundreds of files and it takes 45mnts to copy all the files. &lt;BR /&gt;&lt;BR /&gt;It is not possible to use the command provided by the operating system, because it has been turned off by the administrators for security reasons. &lt;BR /&gt;</description>
      <pubDate>Fri, 29 Apr 2022 18:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/810728#M319731</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-04-29T18:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: What is the fastest and saves way to copy files without x command</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/811440#M320053</link>
      <description>&lt;P&gt;I used:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt; filename insas "&amp;amp;&amp;amp;&amp;amp;KOPIE_&amp;amp;type._&amp;amp;i." recfm=n;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;filename oussas "&amp;amp;doeldir/&amp;amp;&amp;amp;Inname." recfm=n;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt; data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;length msg $ 384;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;rc=fcopy('insas', 'oussas');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;if rc=0 then&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;put 'Copied SRC to DEST.';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;else do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;msg=sysmsg();&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;put rc= msg=;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;filename insas clear;&lt;BR /&gt;filename oussas clear;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of de byte for byte copy. It is way faster, i copied 379 source files (.sas, and .egp) within a minute.&lt;/P&gt;
&lt;P&gt;How do i know of a file is binary or not. I used now the binary method?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am gonna test next week more, by opening a egp file before i copy and also open 1 when i copy to check if anything is blocking or being corrupted.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 13:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-fastest-and-saves-way-to-copy-files-without-x/m-p/811440#M320053</guid>
      <dc:creator>Faruk</dc:creator>
      <dc:date>2022-05-04T13:24:58Z</dc:date>
    </item>
  </channel>
</rss>

