<?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 Import text file contest to corresponding cells in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320898#M70744</link>
    <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;I have a folder containing a number of text file (.txt)&lt;/P&gt;
&lt;P&gt;What I want to do is to create a SAS table, containing two columns:&lt;/P&gt;
&lt;P&gt;one column contains the filename&lt;/P&gt;
&lt;P&gt;The scond column contains the content of the text file. So I want all the contents of each file imported into one cell in column 2 with the correspoing file name in column 1&lt;/P&gt;
&lt;P&gt;I know it might sound "messy" to put all the contents of a file in 1 cell but that is the exactly what I need&lt;/P&gt;
&lt;P&gt;Any help is appreciated&lt;/P&gt;
&lt;P&gt;Merry Christmas to you all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Dec 2016 10:53:52 GMT</pubDate>
    <dc:creator>ammarhm</dc:creator>
    <dc:date>2016-12-23T10:53:52Z</dc:date>
    <item>
      <title>Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320898#M70744</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;
&lt;P&gt;I have a folder containing a number of text file (.txt)&lt;/P&gt;
&lt;P&gt;What I want to do is to create a SAS table, containing two columns:&lt;/P&gt;
&lt;P&gt;one column contains the filename&lt;/P&gt;
&lt;P&gt;The scond column contains the content of the text file. So I want all the contents of each file imported into one cell in column 2 with the correspoing file name in column 1&lt;/P&gt;
&lt;P&gt;I know it might sound "messy" to put all the contents of a file in 1 cell but that is the exactly what I need&lt;/P&gt;
&lt;P&gt;Any help is appreciated&lt;/P&gt;
&lt;P&gt;Merry Christmas to you all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 10:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320898#M70744</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-12-23T10:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320903#M70746</link>
      <description>&lt;P&gt;Well, your request doesn't make much sense, but it is possible:&lt;/P&gt;
&lt;PRE&gt;/* Note this is for Windows*/

filename tmp pipe 'dir "&amp;lt;path to your files&amp;gt;\*.txt" /b';
&lt;BR /&gt;/* Empty overall dataset */&lt;BR /&gt;proc sql;&lt;BR /&gt;  create table FINAL (fname char(2000),data_from_file char(2000);&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;/* Create code to read in each file, set filename and append to empty from above */
data _null_;
  length f $200;
  infile tmp dlm='¬';
  call execute('data tmp; 
                  infile "&amp;lt;path to your files&amp;gt;\'||strip(_infile_)||'";
                  length fname data_from_file $2000;
                  fname="'||strip(_infile_)||'";
                  input data_from_file $;
                run;&lt;BR /&gt;                proc append base=final data=tmp;&lt;BR /&gt;                run;'); 
run;
&lt;/PRE&gt;
&lt;P&gt;Note, I have not tested - but it should be pretty close.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 11:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320903#M70746</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-23T11:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320904#M70747</link>
      <description>&lt;P&gt;I know it dosent make sense... here is afurther explanation&lt;/P&gt;
&lt;P&gt;I have a collection of files for different items, I need to scan each file for keywords, for some keywords, if the keyword is there I will need to give a certain variable a value of 1, for other values, if the keyword is there I need to extract the numbers after that keyword&lt;/P&gt;
&lt;P&gt;That is why i am importing the text files to process them further in SAS, but maybe there is a more efficient way of doing this?&lt;/P&gt;
&lt;P&gt;Kind regrds&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 11:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320904#M70747</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-12-23T11:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320907#M70749</link>
      <description>&lt;P&gt;The other problem witht the code above is that I will break up the text in the file into multiple rows.... which will limit the possibility of finding a text (much easier in a single cell)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 11:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320907#M70749</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-12-23T11:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320913#M70750</link>
      <description>&lt;P&gt;So where are these files coming from/used for? &amp;nbsp;There are many text analytics software out there, SAS has one for instance. &amp;nbsp;It would be better than trying to re-invent it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to show some examples of what you mean, i.e. a text file with some data which illustrates your question and what you want out.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 11:48:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320913#M70750</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-23T11:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320914#M70751</link>
      <description>&lt;P&gt;Since the max length for a character variable is 32767, often a file will not fit into the one varibale.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is easy to read in all files from a directory using wirdcards, you will then get one observation for each record. You can still check for the conditions and set some flags. the FILENAME= option will give you the name of the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fileContents;
  length extFilename _extFilename $ 1024;
  length extLine $ 32767;
  infile "c:\temp\*.txt" filename=_extFilename truncover ;
  extFilename = _extFilename;
  input
    @1 extLine
  ;
  lineLength = length(extLine);
  keep extFilename extLine lineLength;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 11:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320914#M70751</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-12-23T11:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320916#M70753</link>
      <description>&lt;P&gt;THank you&lt;/P&gt;
&lt;P&gt;The files are less than 32000 characters&lt;/P&gt;
&lt;P&gt;When I use your code, the text is still broken into several rows.... any solution for that, thank you&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 12:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320916#M70753</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-12-23T12:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320917#M70754</link>
      <description>&lt;P&gt;Here is an example of the content of a text file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Item not functional, production date 1/7/1993. Meta-data downloaded from the unit showing elevated pressure. Unit sent to location 40 for repair. Unit returned 1/6/2016&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So there many files containing information about different units, the unit number is the file name&lt;/P&gt;
&lt;P&gt;If the text contains the words "unit returned" then I want to put the value "yes" to column "Returned"&lt;/P&gt;
&lt;P&gt;Also, extracting production date and return date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 12:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320917#M70754</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2016-12-23T12:07:13Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320918#M70755</link>
      <description>&lt;P&gt;If you don't need the rest of the text, read the file in word by word. &amp;nbsp;In a minor change to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt;&amp;nbsp;excellent code:&lt;/P&gt;
&lt;PRE&gt;data fileContents;
  length word extFilename _extFilename $ 1024;
  infile "c:\temp\*.txt" filename=_extFilename truncover dlm=" .,:;";
  extFilename = _extFilename;
  input word $;
  output;
  keep extFilename extLine lineLength;
run;&lt;/PRE&gt;
&lt;P&gt;Will create a dataset called filecontents which holds two variables, filename and individual words as observations. &amp;nbsp;Then you can easily check if there is an occurence of specified text (upcase), and pull out dates etc. &amp;nbsp;Then just drop the data you don't want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 12:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320918#M70755</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-23T12:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320920#M70756</link>
      <description>&lt;P&gt;There was a problem in my previous code, since it would not read all the data, find below a new sample that will read all the file into one SAS data set, one record = one obs. A second DATA Step will then put all values into one variable, but as already mentioned, there is a limit. Find also a DS2 program that does the same, except, you can have longer variables (as long as your in DS2).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fileContents;
  length extFilename _extFilename $ 1024;
  length extLine $ 32767;
  infile "c:\temp\*.txt" filename=_extFilename truncover end=last;
  row + 1;
  input
    @1 extLine $32767.
  ;
  extFilename = _extFilename;
run;

proc sort data=fileContents;
  by extFilename row;
run;

data want;
  set fileContents;
  length fileContents $ 32767;
  retain fileContents;
  by extFilename;

  if first.extFilename = 1 then do;
    fileContents = ' ';
  end;

  fileContents = cats(fileContents, extLine);

  if last.extFilename = 1 then do;
    extLineLength = length(fileContents);
    output;
  end;
run;

proc ds2;

  data want(overwrite=yes);
    dcl varchar(10485760) fileContents;
    retain fileContents;

    method run();
      dcl int extLineLength;
      dcl varchar(1024) eFilename;
      set fileContents;
      by extFilename;

      if first.extFilename = 1 then do;
        fileContents = ' ';
      end;

      fileContents = cats(fileContents, extLine);

      if last.extFilename = 1 then do;
        /* do something here with the file contents */
        extLineLength = length(fileContents);
      end;
    end;

  enddata;
run;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 13:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320920#M70756</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-12-23T13:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320921#M70757</link>
      <description>&lt;P&gt;Your on Windows? Are you using SAS Base with x command? Using a command line to search the text file is goimg to be much faster than SAS&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 13:41:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320921#M70757</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-23T13:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320922#M70758</link>
      <description>&lt;P&gt;See the last set of examples here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://technet.microsoft.com/en-us/library/bb490907.aspx" target="_blank"&gt;https://technet.microsoft.com/en-us/library/bb490907.aspx&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Dec 2016 13:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/320922#M70758</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-23T13:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Import text file contest to corresponding cells</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/321032#M70802</link>
      <description>&lt;PRE&gt;
I would more like filename + filevar= , which could give you more flexibility .


data want;
input fname $80.;
infile dummy filevar=fname length=len end=last;
do while(not last);
 filename=fname;
 input content $varying2000. len;
 output;
end;
cards;
/folders/myfolders/x.txt
/folders/myfolders/y.txt
;
run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Dec 2016 06:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-text-file-contest-to-corresponding-cells/m-p/321032#M70802</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-24T06:17:34Z</dc:date>
    </item>
  </channel>
</rss>

