<?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: Error using FCOPY Function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718185#M222214</link>
    <description>&lt;P&gt;The answer is in my previous post. Please read the code closely, you will find that I used the "binary" method for a csv file without problems.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Feb 2021 11:18:13 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-02-10T11:18:13Z</dc:date>
    <item>
      <title>Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/716986#M221683</link>
      <description>&lt;P&gt;I've the code as below to move the files from source to target. When I tried to execute the code below, I've got error as,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR: Unable to copy. source=/var/sasdata/INPUT/GT/IFR_GH_MSTD_0069.xlsx
target=/var/sasdata/INPUT/LH/IFR_GH_MSTD_0069.xlsx rc3=-7440230
msg=WARNING: 3 records were truncated when the FCOPY function read from fileref FROM. 0 records were truncated when the FCOPY functi
on wrote to fileref TO. To prevent the truncation of records in future operations, you can increase the amount of space needed t
NOTE: There were 2 observations read from the data set WORK.FILES_TARGET_CHECK.&lt;/PRE&gt;
&lt;P&gt;What would be likely cause for thsi error? After the execution of the program I want both .xlsx and .csv file to move to target folder but only .csv has moved. Program which I used is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data files_moved;
  set files_target_check ;
  length rc1-rc4 8 msg $256 ;

  /*Copy and delete*/
  if not (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) or index(lowcase(filename),'_copied.csv ')  then do;
  rc1=filename('from',source);
  rc2=filename('to',target);
  rc3=fcopy('from','to');
  if rc3 then do;
    msg=sysmsg(); 
    put 'ERROR: Unable to copy. ' source= target= rc3= msg=;
  end;
  else do;
    rc4=fdelete('from');
  end;
  output;
  end;
  rc1=filename('from');
  rc2=filename('to');
run;&lt;/PRE&gt;
&lt;P&gt;Data from files_target_check is,&lt;/P&gt;
&lt;TABLE width="1707"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="343"&gt;&lt;STRONG&gt;filename&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="610"&gt;&lt;STRONG&gt;source&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="682"&gt;&lt;STRONG&gt;target&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="72"&gt;&lt;STRONG&gt;flag&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;IFR_GH_MSTD_0069.xlsx&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/INPUT/GT/IFR_GH_MSTD_0069.xlsx&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/INPUT/LH/IFR_GH_MSTD_0069.xlsx&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;IFR_GH_TRND_1_0069_1_20201009T075212.csv&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/INPUT/GT/IFR_GH_TRND_1_0069_1_20201009T075212.csv&lt;/TD&gt;
&lt;TD&gt;/var/sasdata/INPUT/LH/IFR_GH_TRND_1_0069_1_20201009T075212.csv&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 07:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/716986#M221683</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-05T07:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717187#M221764</link>
      <description>&lt;P&gt;I suspect the "what" is that the xlsx file format is actually 1) a zip file and 2) multiple compressed XML files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "why" might be the use of the wrong function. From the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;H1 id="n10dz22b5ixohin1vwzilweetek0" class="xis-title"&gt;&lt;A name="~1" target="_blank"&gt;&lt;/A&gt;&lt;FONT style="background-color: #fcdec0;"&gt;FCOPY&lt;/FONT&gt; Function&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Copies records from one fileref to another fileref, and returns a value that indicates whether the records were successfully copied&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Fcopy copies records, which in a simple text file such as CSV, are lines of data. XML is not like that (open&amp;nbsp; an XML in a text editor and see the difference) so I am not sure what Fcopy may see as a "record" in such.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 19:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717187#M221764</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-05T19:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717302#M221799</link>
      <description>Can I understand that issue might be with the file and the program is&lt;BR /&gt;right?&lt;BR /&gt;</description>
      <pubDate>Sat, 06 Feb 2021 13:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717302#M221799</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-06T13:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717311#M221802</link>
      <description>.xlsx files are binary files, so treat them that way - see this example in the online doc at&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1srxqduw2jfagn1fbfcc5d5d249" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1srxqduw2jfagn1fbfcc5d5d249&lt;/A&gt;</description>
      <pubDate>Sat, 06 Feb 2021 15:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717311#M221802</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2021-02-06T15:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717360#M221827</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15174"&gt;@Peter_C&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;can't we move .xlsx and .csv file in one single data step as shown below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data files_moved;
  set files_target_check ;
  length rc1-rc4 8 msg $256 ;

  /*Copy and delete*/
  if not (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) or index(lowcase(filename),'_copied.csv ')  then do;
  rc1=filename('from',source);
  rc2=filename('to',target);
  rc3=fcopy('from','to');
  if rc3 then do;
    msg=sysmsg(); 
    put 'ERROR: Unable to copy. ' source= target= rc3= msg=;
  end;
  else do;
    rc4=fdelete('from');
  end;
  output;
  end;
  rc1=filename('from');
  rc2=filename('to');
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Feb 2021 06:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717360#M221827</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-07T06:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717362#M221828</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;Example 2 of the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n10dz22b5ixohin1vwzilweetek0.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FCOPY Function&lt;/A&gt;&amp;nbsp;shows how to copy a binary file. Important: use RECFM=N for the file reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Edit: changed the RECFM to N, as it is in the documentation (typo, my bad)&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/717362#M221828</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-10T09:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718130#M222181</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Is it recfm=n or recfm=f? How to use RECFM in my program below as I do not have filename statement (used only filename function)&amp;nbsp;due to the fact that filename is dynamic. Sometimes I receive .xlsx and sometime .csv otherewise both CSV and Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data files_moved;
  set files_target_check ;
  length rc1-rc4 8 msg $256 ;

  /*Copy and delete*/
  if not (scan(lowcase(filename),5,'_') in ('5601','6010','6020')) or index(lowcase(filename),'_copied.csv ')  then do;
  rc1=filename('from',source);
  rc2=filename('to',target);
  rc3=fcopy('from','to');
  if rc3 then do;
    msg=sysmsg(); 
    put 'ERROR: Unable to copy. ' source= target= rc3= msg=;
  end;
  else do;
    rc4=fdelete('from');
  end;
  output;
  end;
  rc1=filename('from');
  rc2=filename('to');
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 06:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718130#M222181</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-10T06:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718143#M222192</link>
      <description>&lt;P&gt;Hi, for copying files I generally use the byte-for-byte technique including setting the chunksize to speed up the copying process&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   %*-------------------------------------------------------------------------;
   %* Set source and target (copy) path and file name values:                 ;
   %*-------------------------------------------------------------------------;

   %let infile = %str();
   %let outfile = %str();

   %*-------------------------------------------------------------------------;
   %* Set copy mode and chunksize variables:                                  ;
   %*-------------------------------------------------------------------------;

   %let mode = S ; /* I (chunksize is 1) / S (use chunksize value) */
   %let chunksize = 32767 ; /* 1 - 32767 */

   %*-------------------------------------------------------------------------;
   %* Copy INFILE to OUTFILE using the byte-for-byte method:                  ;
   %*-------------------------------------------------------------------------;

   filename in "&amp;amp;infile.";
   filename out "&amp;amp;outfile.";

   data _null_;

      length 
         ifile  8 
         ofile  8
         fmtlen 8
         bytes  8
         outfmt $ 32
         rec    $ &amp;amp;chunksize.
         ;

      ifile = fopen('in',"&amp;amp;mode.",&amp;amp;chunksize.,'B');
      ofile = fopen('out','O',&amp;amp;chunksize.,'B');
      bytes = 0;
      rec   = '20'x;

      do while(fread(ifile) eq 0);

         call missing(outfmt, rec);
         rc = fget(ifile,rec,&amp;amp;chunksize.);

         if "%upcase(&amp;amp;mode.)" eq "I" then do;
            fmtlen = 1;
            outfmt = 1;
         end;
         else do;
            fcolin = fcol(ifile);
            if (fcolin - &amp;amp;chunksize.) eq 1 then do;
              fmtlen = &amp;amp;chunksize.;
            end;
            else do;
              fmtlen = fcolin - 1;
            end;
            outfmt = cats("$char", fmtlen, ".");
         end;

         bytes + fmtlen;

         rc = fput(ofile,putc(rec,outfmt));
         rc = fwrite(ofile);

      end;

      call symputx('size', bytes);

      rc = fclose(ifile);
      rc = fclose(ofile);

   run;

   filename in clear;
   filename out clear;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   %put File %scan(&amp;amp;infile.,-1,/\) copied to %scan(&amp;amp;outfile.,-1,/\).;
   %put Transferred &amp;amp;size. Bytes.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718143#M222192</guid>
      <dc:creator>PaulCanals</dc:creator>
      <dc:date>2021-02-10T09:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718163#M222203</link>
      <description>&lt;P&gt;Sorry about the confusion, the RECFM has to be N (when there's a contradiction between me and the documentation, the documentation is most probably correct).&lt;/P&gt;
&lt;P&gt;You need to supply the options in a separate parameter of the FILENAME function, and you can copy text files as binary without problems:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc export
  data=sashelp.class
  file="/folders/myfolders/class.xlsx"
  dbms=xlsx
  replace
;
run;

proc export
  data=sashelp.class
  file="/folders/myfolders/class.csv"
  dbms=csv
  replace
;
run;

data _null_;
rc = filename("from","/folders/myfolders/class.xlsx","","recfm=n");
put rc=;
rc = filename("to","/folders/myfolders/test/class.xlsx","","recfm=n");
put rc=;
rc = fcopy("from","to");
put rc=;
rc = filename("from","/folders/myfolders/class.csv","","recfm=n");
put rc=;
rc = filename("to","/folders/myfolders/test/class.csv","","recfm=n");
put rc=;
rc = fcopy("from","to");
put rc=;
run;

proc import
  datafile="/folders/myfolders/test/class.xlsx"
  dbms=xlsx
  out=work.class1
  replace
;
run;

proc import
  datafile="/folders/myfolders/test/class.csv"
  dbms=csv
  out=work.class2
  replace
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code runs without ERRORs or WARNINGs, and creates two (nearly) identical datasets in WORK.&lt;/P&gt;
&lt;P&gt;The values are identical, but some attributes differ (formats, informats) because of PROC IMPORT.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 09:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718163#M222203</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-10T09:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718180#M222212</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;what will happen if I use recfm=n for CSV files as I shown below? Because in real life I may transfer CSV or Excel file or both&amp;nbsp; as files are dynamic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
rc = filename("from","/folders/myfolders/class.csv","","recfm=n");&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 11:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718180#M222212</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-02-10T11:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718185#M222214</link>
      <description>&lt;P&gt;The answer is in my previous post. Please read the code closely, you will find that I used the "binary" method for a csv file without problems.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 11:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/718185#M222214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-10T11:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Error using FCOPY Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/782893#M249582</link>
      <description>&lt;P&gt;For reference we recently published a macro that will (binary) copy ALL files in a particular directory, and recursively so:&amp;nbsp;&amp;nbsp;&lt;A href="https://core.sasjs.io/mp__copyfolder_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__copyfolder_8sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 12:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-using-FCOPY-Function/m-p/782893#M249582</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2021-11-29T12:24:23Z</dc:date>
    </item>
  </channel>
</rss>

