<?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: How to import 100 TXT files to 100 Rows in one dataset? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343494#M63391</link>
    <description>&lt;P&gt;This version reads the file 32767 bytes at a time TERMSTRs and all into an array of TEXT variables.&amp;nbsp; This will capture all text for files that may be larger than 32767.&amp;nbsp; Adjust array diminsion as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file;
   length file filenm $64;
   retain file;
   array text[10] $32767;
   retain text;
   infile '~/*.dat' eov=eov end=end filename=filenm recfm=F lrecl=32767;
   input;
   *list;
   if _n_ eq 1 or eov then do;      
      if eov then output;
      file=filenm;
      eov=0;
      call missing(of i text[*]);
      end;
   i + 1;
   text[i]=_infile_;
   if end then output;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 20:24:38 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2017-03-22T20:24:38Z</dc:date>
    <item>
      <title>How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343429#M63381</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I would like to&amp;nbsp;import&amp;nbsp;100 TXT files to 100 rows in one dataset.&lt;/P&gt;&lt;P&gt;2. To read 1 file to 1 row in 1 Dataset, I can use the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;length text $32767;&lt;BR /&gt;retain text '';&lt;BR /&gt;infile "C:\Test.txt" flowover dlmstr='//' end=last;&lt;BR /&gt;input;&lt;BR /&gt;text=cats(text,_infile_);&lt;BR /&gt;if last then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. However, I would like to run&amp;nbsp;&lt;SPAN&gt;import&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;100 TXT files (from the same directory) to 100 rows in one dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;D&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 17:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343429#M63381</guid>
      <dc:creator>DanielDor</dc:creator>
      <dc:date>2017-03-22T17:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343434#M63382</link>
      <description>&lt;P&gt;Do your txt files have column headings?&lt;/P&gt;
&lt;P&gt;Are you absolutely sure that 32767 characters will hold the entire contents of each file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;did you try?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;infile "C:\path:\*.txt" flowover dlmstr='//' end=last;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where path is the path to the folder&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will attempt to read all of the files with txt as the extension in the folder. If there is a more specific pattern to the file names&amp;nbsp;you need to extract then more details on the names is needed.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 17:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343434#M63382</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-22T17:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343454#M63384</link>
      <description>&lt;P&gt;This use wildcard in the INFILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added a variable file to show where each record comes from.&amp;nbsp; DLMSTR doesn't seem to do anything.&amp;nbsp; Are you trying to keep the TERMSTR on the records in TEXT?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file;
   length file filenm $64;
   retain file;
   infile '~/t00*.dat' eov=eov end=end dlmstr='//' flowover filename=filenm;
   length text $32767;
   retain text;
   input;
   if _n_ eq 1 or eov then do;      
      if eov then output;
      file=filenm;
      eov=0;
      call missing(text);
      end;
   text=cats(text,_infile_);
   if end then output;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Mar 2017 18:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343454#M63384</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-03-22T18:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343471#M63386</link>
      <description>Thanks so much! This is working just great &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Appreciate your fast reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 22 Mar 2017 19:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343471#M63386</guid>
      <dc:creator>DanielDor</dc:creator>
      <dc:date>2017-03-22T19:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343473#M63387</link>
      <description>Thanks a lot for your fast reply..Changing the script the way you suggested, imported all the text files to the final row of the dataset, so it is not exactly what I looked for. Thanks anyway for your great explanation &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 22 Mar 2017 19:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343473#M63387</guid>
      <dc:creator>DanielDor</dc:creator>
      <dc:date>2017-03-22T19:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343494#M63391</link>
      <description>&lt;P&gt;This version reads the file 32767 bytes at a time TERMSTRs and all into an array of TEXT variables.&amp;nbsp; This will capture all text for files that may be larger than 32767.&amp;nbsp; Adjust array diminsion as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file;
   length file filenm $64;
   retain file;
   array text[10] $32767;
   retain text;
   infile '~/*.dat' eov=eov end=end filename=filenm recfm=F lrecl=32767;
   input;
   *list;
   if _n_ eq 1 or eov then do;      
      if eov then output;
      file=filenm;
      eov=0;
      call missing(of i text[*]);
      end;
   i + 1;
   text[i]=_infile_;
   if end then output;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 20:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343494#M63391</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-03-22T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343605#M63410</link>
      <description>&lt;P&gt;Thanks! That also working great. As you said, it is working for texts above 32K chars.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 06:56:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343605#M63410</guid>
      <dc:creator>DanielDor</dc:creator>
      <dc:date>2017-03-23T06:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to import 100 TXT files to 100 Rows in one dataset?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343746#M63426</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* T1003210 load a file in one character variable(mystring) of length 128,004.

Associated problem. We really need to what the op wants to do with the 
array of 32k chunks. 


I load a file in one character variable(mystring) of length 128,004.

This type of problem is best solved with Perl or Python.
I present an R solution because I am a little more skilled in R.

inspired
https://goo.gl/eOu829
https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343429

HAVE (A file with two 64000 byte records)
=========================================

FILE:  d:/txt/fyl1

RECORD 1:    64002   bytes  first recrord  (crlf once)
RECORD 2:   128004   bytes  full file (crlf twice)

WANT ( load the the file both records into one character variable of length 128,004 bytes)
==========================================================================================

Pull some substrings out

   1] "FILE LENGTH"
   1] 128004

   1] "substr(mystring,60001,60010)"
   1] "1234567890"

   1] "substr(mystring,30001,30010)"
   1] "1234567890"

*                _                  _       _
 _ __ ___   __ _| | _____        __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| |   &amp;lt;  __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___|      \__,_|\__,_|\__\__,_|

;

data _null_;
  length txt1 txt2 $32000;
  txt1=repeat('1234567890',3199);
  txt2=txt1;
  do fyls=1 to 1;
    fylvar=cats('d:/txt/fyl',put(fyls,1.));
    file dummy filevar=fylvar lrecl=64000 recfm=v;
    put txt1 +(-1) txt2;
    put txt1 +(-1) txt2;
  end;
run;quit;

NOTE: 2 records were written to the file DUMMY.
      The minimum record length was 64000.

*____
|  _ \
| |_) |
|  _ &amp;lt;
|_| \_\

;


%utl_submit_r64('
library(readr);
mystring &amp;lt;- read_file("d:/txt/fyl1");
"FILE LENGTH";
nchar(mystring);
"substr(mystring,60001,60010)";
substr(mystring,60001,60010);
"substr(mystring,30001,30010)";
substr(mystring,30001,30010);
');


1] "FILE LENGTH"
1] 128004

1] "substr(mystring,60001,60010)"
1] "1234567890"

1] "substr(mystring,30001,30010)"
1] "1234567890"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Mar 2017 15:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-import-100-TXT-files-to-100-Rows-in-one-dataset/m-p/343746#M63426</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-23T15:06:31Z</dc:date>
    </item>
  </channel>
</rss>

