<?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: Howto: copy excel file using infile/input and file/put in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45191#M9309</link>
    <description>HI Darryl&lt;BR /&gt;
&lt;BR /&gt;
I'm not using EG and I can easily solve the problem using the X command, CALL SYSTEM or simlilar. (sorry, should have stated that more clearly in my first post)&lt;BR /&gt;
&lt;BR /&gt;
My &lt;B&gt;curiosity&lt;/B&gt; was regarding the opportunity to use the DATA STEP statements infile/input and file/put to 'copy' an Excel file.</description>
    <pubDate>Wed, 07 Jul 2010 21:59:20 GMT</pubDate>
    <dc:creator>GertNissen</dc:creator>
    <dc:date>2010-07-07T21:59:20Z</dc:date>
    <item>
      <title>Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45187#M9305</link>
      <description>I have asked for this once, but havent found an answer.&lt;BR /&gt;
&lt;BR /&gt;
I wan't to find a method to copy an Excel file from one location til another using a datastep with infile/input and file/put statements.&lt;BR /&gt;
&lt;BR /&gt;
I'm trying to learn how to do this using SAS and not by using OS copy or similar.&lt;BR /&gt;
&lt;BR /&gt;
I'm looking for something like&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename input;&lt;BR /&gt;
filename output;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  infile input;&lt;BR /&gt;
  input;&lt;BR /&gt;
  file output;&lt;BR /&gt;
  put _infile_;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
This code will not work for an Excel file (works fine with textfiles), and I need to find the proper options etc.</description>
      <pubDate>Wed, 07 Jul 2010 08:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45187#M9305</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2010-07-07T08:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45188#M9306</link>
      <description>May I ask why you want to do this?&lt;BR /&gt;
&lt;BR /&gt;
Is it because shell escapes are disables in your environment as this is the default setting for EGuide (noxcmd)?&lt;BR /&gt;
&lt;BR /&gt;
If shell escapes are possible then I would recommend you use OS copy.</description>
      <pubDate>Wed, 07 Jul 2010 10:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45188#M9306</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-07-07T10:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45189#M9307</link>
      <description>Hi Patrick&lt;BR /&gt;
&lt;BR /&gt;
I'm not using EG and I can easily solve the problem using x command, call system or simlilar. (sorry, should have stated that in my question)&lt;BR /&gt;
&lt;BR /&gt;
I was just wondering how I could read a binary file and write it back using only datastep statements. I'm curious and would like to try it &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; but failed ;-(&lt;BR /&gt;
&lt;BR /&gt;
I have somewhat similar problem (batch job) where I want to write a file (Excel) to the webdav (overwrite). If you have a solution for this, I'm also interessted &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Wed, 07 Jul 2010 10:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45189#M9307</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2010-07-07T10:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45190#M9308</link>
      <description>You could use the CALL SYSTEM function from within a DATA STEP.&lt;BR /&gt;
&lt;BR /&gt;
Or you can utilize SAS's abiltiy to call OS DLLs by using the SASCBTBL attribute table with the MODULE family of functions and call routines.  I have just finished writing a paper for SESUG and NESUG regarding this topic.  My install of SAS is EG and the X command and SYSTASK functions are turned off, so the SASCBTBL access method works great.&lt;BR /&gt;
&lt;BR /&gt;
The below papers are a good start.&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/248-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/248-30.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
and in the SAS Online Doc&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#/documentation/cdl/en/hostwin/63285/HTML/default/accdll.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/viewer.htm#/documentation/cdl/en/hostwin/63285/HTML/default/accdll.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Darryl</description>
      <pubDate>Wed, 07 Jul 2010 12:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45190#M9308</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2010-07-07T12:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45191#M9309</link>
      <description>HI Darryl&lt;BR /&gt;
&lt;BR /&gt;
I'm not using EG and I can easily solve the problem using the X command, CALL SYSTEM or simlilar. (sorry, should have stated that more clearly in my first post)&lt;BR /&gt;
&lt;BR /&gt;
My &lt;B&gt;curiosity&lt;/B&gt; was regarding the opportunity to use the DATA STEP statements infile/input and file/put to 'copy' an Excel file.</description>
      <pubDate>Wed, 07 Jul 2010 21:59:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45191#M9309</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2010-07-07T21:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45192#M9310</link>
      <description>If I'm not mistaken since Excel is a binary file type the INFILE/FILE/PUT statements will not work.  SAS is expecting a text type file looking for end of record markers etc...&lt;BR /&gt;
&lt;BR /&gt;
Darryl</description>
      <pubDate>Thu, 08 Jul 2010 11:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45192#M9310</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2010-07-08T11:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45193#M9311</link>
      <description>Yes, Excel files are binary files. I will not read the Excel file to extract data&lt;BR /&gt;
&lt;BR /&gt;
With DATA _null_; You can read/write everything with infile/file and I was hoping thath RECFM=S and nbyte= could be used, in combination with put _infile_ $varying. len; like below....&lt;BR /&gt;
&lt;BR /&gt;
I Have found these resources, but no breakthrough yet.&lt;BR /&gt;
&lt;BR /&gt;
Usage Note 6588: Serving binary files when running the IntrNet Application Server&lt;BR /&gt;
 - &lt;A href="http://support.sas.com/kb/6/588.html" target="_blank"&gt;http://support.sas.com/kb/6/588.html&lt;/A&gt;&lt;BR /&gt;
Problem Note 3404: The "_INFILE_" INPUT/PUT statement option is inconsistent with binary mode I/O&lt;BR /&gt;
 - &lt;A href="http://support.sas.com/kb/3/404.html" target="_blank"&gt;http://support.sas.com/kb/3/404.html&lt;/A&gt;&lt;BR /&gt;
Writing MS Office and other binary files &lt;BR /&gt;
 - &lt;A href="http://support.sas.com/forums/thread.jspa?threadID=5735" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=5735&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   data _null_;&lt;BR /&gt;
     length char $1;&lt;BR /&gt;
	  infile dav length=len lrecl=32767 nbyte=nbyt;&lt;BR /&gt;
	  nbyt = -1;&lt;BR /&gt;
	  input;&lt;BR /&gt;
	  file target lrecl=32767;&lt;BR /&gt;
	  do i = 1 to len;&lt;BR /&gt;
		 char = substr(_infile_,i,1);&lt;BR /&gt;
		 put char $char1. @@;&lt;BR /&gt;
	  end;&lt;BR /&gt;
	run;&lt;BR /&gt;
[pre]</description>
      <pubDate>Thu, 08 Jul 2010 12:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45193#M9311</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2010-07-08T12:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45194#M9312</link>
      <description>Test the following.  &lt;BR /&gt;
&lt;BR /&gt;
I used the DOS COMP command to compare the files, they compare OK.  &lt;BR /&gt;
[pre]&lt;BR /&gt;
comp testcopy.xls testcopy02.xls&lt;BR /&gt;
Comparing testcopy.xls and testcopy02.xls...&lt;BR /&gt;
Files compare OK&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
And the copy opens as expected in EXCEL. But after opening the copy, but not saving, the compare changes.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Comparing testcopy.xls and test&lt;BR /&gt;
Compare error at OFFSET 666C&lt;BR /&gt;
file1 = A0&lt;BR /&gt;
file2 = C0&lt;BR /&gt;
Compare error at OFFSET 666D&lt;BR /&gt;
file1 = 8D&lt;BR /&gt;
file2 = 9D&lt;BR /&gt;
Compare error at OFFSET 666E&lt;BR /&gt;
file1 = 32&lt;BR /&gt;
file2 = 4&lt;BR /&gt;
Compare error at OFFSET 666F&lt;BR /&gt;
file1 = 2E&lt;BR /&gt;
file2 = FC&lt;BR /&gt;
Compare error at OFFSET 6670&lt;BR /&gt;
file1 = 90&lt;BR /&gt;
file2 = A1&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
TESTCOPY.XLS is just XLS with several sheets in binary EXCEL format.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename FT33F001 'testcopy.xls' recfm=N;&lt;BR /&gt;
filename FT34F001 'testcopy02.xls' recfm=N;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   infile FT33F001;&lt;BR /&gt;
   file FT34F001;&lt;BR /&gt;
   input str $256.;&lt;BR /&gt;
   put str $256.;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: data _null_;

Message was edited by: data _null_;</description>
      <pubDate>Thu, 08 Jul 2010 13:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45194#M9312</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-07-08T13:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45195#M9313</link>
      <description>If I had to guess, I'd guess that the Excel file has an embedded date or time value that changes when the file is opened and that's the difference COMP is finding.</description>
      <pubDate>Thu, 08 Jul 2010 14:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45195#M9313</guid>
      <dc:creator>Tim_SAS</dc:creator>
      <dc:date>2010-07-08T14:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45196#M9314</link>
      <description>Hi _null_&lt;BR /&gt;
&lt;BR /&gt;
A big Tx to you &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
I got it to work with $32767., if I use $256. I can't open the new copy (Excel reports that its damaged). I don't know why ?&lt;BR /&gt;
[pre]&lt;BR /&gt;
filename FT33F001 'D:\temp\test.xls' recfm=N;&lt;BR /&gt;
filename FT34F001 'D:\temp\testcopy.xls' recfm=N;&lt;BR /&gt;
 &lt;BR /&gt;
data _null_;   &lt;BR /&gt;
 infile FT33F001 lrecl=32767;   &lt;BR /&gt;
 file FT34F001 lrecl=32767;   &lt;BR /&gt;
 input str $32767.;   &lt;BR /&gt;
 put str $32767.;   &lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 08 Jul 2010 14:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45196#M9314</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2010-07-08T14:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45197#M9315</link>
      <description>I did a bit more testing. with a larger XL file.  I believe more care must be taken with the last record that is potentially less that LRECL.  See modified version of the program, with I think works as we want.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let lrecl=32767;&lt;BR /&gt;
%let lrecl=4096;&lt;BR /&gt;
filename FT33F001 'testcopy01.xls' recfm=N lrecl=&amp;amp;lrecl;&lt;BR /&gt;
filename FT34F001 'testcopy02.xls' recfm=N lrecl=&amp;amp;lrecl;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   infile FT33F001 length=length;&lt;BR /&gt;
   file FT34F001;&lt;BR /&gt;
   input str $char&amp;amp;lrecl..;&lt;BR /&gt;
   if length ne &amp;amp;lrecl then putlog 'NOTE: ' (_n_ length)(=);&lt;BR /&gt;
   put str $varying&amp;amp;lrecl.. length;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 08 Jul 2010 16:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45197#M9315</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-07-08T16:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45198#M9316</link>
      <description>you almost made it!&lt;BR /&gt;
You just have to deal with two issues&lt;BR /&gt;
1 : to ignore line ending characters (like crlf), use recfm=F (after all it is a binary file)&lt;BR /&gt;
2 : to ignore embedded EOF marks in binary files, use "ignoreDOSeof" infile option.&lt;BR /&gt;
Here is your code , just extended a little [pre]filename  input "%sysget(temp)\tes2.xls" ;&lt;BR /&gt;
filename output "%sysget(temp)\tes3.xls" ;&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   infile input recfm=f ignoreDOSeof ;&lt;BR /&gt;
   file  output recfm=f  ;&lt;BR /&gt;
   input ;&lt;BR /&gt;
   put _infile_ ;&lt;BR /&gt;
run;&lt;BR /&gt;
dm 'winexecfile "%path(output)" ';[/pre]&lt;BR /&gt;
It is possible that I am successful only because my file is a multiple of 256 bytes (the default lrecl= value). If you are concerned, add LRECL=1 to the infile and file options. For my 4 megabyte test workbook, it took my small machine just 2.7 secs real time to handle with LRECL=1 instead of 0.6 secs for the default LRECL=256.&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Thu, 15 Jul 2010 14:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/45198#M9316</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-07-15T14:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Howto: copy excel file using infile/input and file/put</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/284232#M58000</link>
      <description>&lt;P&gt;sorry to bump this as just wanted to add what I found that finally worked for me in similar circumstances:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/kb/20/784.html" target="_blank"&gt;http://support.sas.com/kb/20/784.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; data _null_;
    length data $1;
    INFILE  in_filename  recfm=n;
    file  out_filenmae recfm=n mod;
    input data  $char1. @@;
    put data $char1. @@;
 run;&lt;/PRE&gt;&lt;P&gt;Although this is written for STP web process it should apply when writting to another file as the _webout is similar. The secret seems to be the recfm=n and the @@s.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 02:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Howto-copy-excel-file-using-infile-input-and-file-put/m-p/284232#M58000</guid>
      <dc:creator>hamish_at_nab</dc:creator>
      <dc:date>2016-07-14T02:20:37Z</dc:date>
    </item>
  </channel>
</rss>

