<?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: Macro and data step combination to read multiple text files as a string variable in a SAS datase in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702345#M215108</link>
    <description>&lt;P&gt;Hey Paige,&lt;/P&gt;&lt;P&gt;I appreciate your reply. Recent Google search yielded&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/31848367/filevar-infile-statement-to-read-in-multiple-txt-file" target="_blank"&gt;https://stackoverflow.com/questions/31848367/filevar-infile-statement-to-read-in-multiple-txt-file&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;So I changed the program to read two infiles (first the list of files and second the content of each file) instead of the macro in my earlier program:&lt;/P&gt;&lt;PRE&gt;options mprint;
libname htmdata "C:\Users\Owner\OneDrive - George Mason University - O365 Production\TopCoder";
filename DataIn pipe "dir C:\ContestTextfile\*.txt /S /B"; 
data htmdata.accel ;
  infile DataIn truncover;
    length fil2read $256; 
    input fil2read;
  infile xyz filevar = fil2read dlmstr='//' flowover end=last; 
    length filecontent $32627 ; 
    retain filecontent '';
    do while (not last);
     if _n_ = 1 then input filecontent;
     else do; 
        input; 
        filecontent=cats(filecontent,_infile_);
     end;
    end;
   if last then output;
keep fil2read filecontent;
run;
run;&lt;/PRE&gt;&lt;P&gt;Good news is that the program captures the filecontent variable from all files. However, the fil2read is not getting captured in the htmdata.accel as a column. I have attached the log file as a Word document.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nirup&lt;/P&gt;</description>
    <pubDate>Sun, 29 Nov 2020 20:59:36 GMT</pubDate>
    <dc:creator>nirupmenon</dc:creator>
    <dc:date>2020-11-29T20:59:36Z</dc:date>
    <item>
      <title>Macro and data step combination to read multiple text files as a string variable in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702341#M215105</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;I have multiple files in a directory containing descriptive text. I want to read each file completely into a SAS dataset as variables with the filename in one column and the entire text from each file as the second variable. There should be as many rows in the output dataset as files in the directory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I followed Chris H.'s blog&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2016/07/12/how-to-read-the-contents-of-a-file-into-a-sas-macro-variable/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2016/07/12/how-to-read-the-contents-of-a-file-into-a-sas-macro-variable/&lt;/A&gt;&amp;nbsp;and set the code as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro fileread; /* run this macro for each file in the directory*/&lt;BR /&gt;data null;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; length filecontent $1000 textcontent $32627 ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; retain filecontent '';&lt;BR /&gt;&amp;nbsp; infile "C:\ContestTextfile\&amp;amp;filein..txt" dlmstr='//' flowover end=last;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %if _n_ = 1 %then input filecontent;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %else %do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;input;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let filecontent=cats(filecontent,_infile_);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; if last then call symput('textcontent', filecontent);&lt;BR /&gt;&amp;nbsp;run;&lt;BR /&gt;%mend fileread;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* the data step below uses the file list in the directory to assign each file name to a macro variable */&lt;BR /&gt;data htmdata.accel (keep=fname filecontent); set htmdata.file_list;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;length filecontent $32627 ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;call symput('filein', trim(fname)); /* put the file name from the file list in a macro variable */&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%fileread; /* run the macro for each file in the file list */&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%let filecontent = textcontent;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is two columns in the dataset: File_Name File_Content.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I get multiple errors with the above code: 1) both filecontent and textcontent are uninitialized; 2)&amp;nbsp; the output file htmdata.accel contains only fname which was read from the file_list dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would appreciated. Thanks!&lt;/P&gt;&lt;P&gt;Nirup&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 19:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702341#M215105</guid>
      <dc:creator>nirupmenon</dc:creator>
      <dc:date>2020-11-29T19:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro and data step combination to read multiple text files as a string variable in a SAS datase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702344#M215107</link>
      <description>&lt;P&gt;If you get errors, show us the LOG. Run the program again with &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as the first command.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need to see the complete log of one of these steps that has an error, that's 100% of the log for one of those steps, with nothing chopped out. Format the log properly by copying it as text and pasting it into the window that appears when you click on the &amp;lt;/&amp;gt; icon here. Do not provide the log any other way.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 20:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702344#M215107</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-29T20:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro and data step combination to read multiple text files as a string variable in a SAS datase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702345#M215108</link>
      <description>&lt;P&gt;Hey Paige,&lt;/P&gt;&lt;P&gt;I appreciate your reply. Recent Google search yielded&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/31848367/filevar-infile-statement-to-read-in-multiple-txt-file" target="_blank"&gt;https://stackoverflow.com/questions/31848367/filevar-infile-statement-to-read-in-multiple-txt-file&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;So I changed the program to read two infiles (first the list of files and second the content of each file) instead of the macro in my earlier program:&lt;/P&gt;&lt;PRE&gt;options mprint;
libname htmdata "C:\Users\Owner\OneDrive - George Mason University - O365 Production\TopCoder";
filename DataIn pipe "dir C:\ContestTextfile\*.txt /S /B"; 
data htmdata.accel ;
  infile DataIn truncover;
    length fil2read $256; 
    input fil2read;
  infile xyz filevar = fil2read dlmstr='//' flowover end=last; 
    length filecontent $32627 ; 
    retain filecontent '';
    do while (not last);
     if _n_ = 1 then input filecontent;
     else do; 
        input; 
        filecontent=cats(filecontent,_infile_);
     end;
    end;
   if last then output;
keep fil2read filecontent;
run;
run;&lt;/PRE&gt;&lt;P&gt;Good news is that the program captures the filecontent variable from all files. However, the fil2read is not getting captured in the htmdata.accel as a column. I have attached the log file as a Word document.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Nirup&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 20:59:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702345#M215108</guid>
      <dc:creator>nirupmenon</dc:creator>
      <dc:date>2020-11-29T20:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro and data step combination to read multiple text files as a string variable in a SAS datase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702355#M215113</link>
      <description>&lt;P&gt;Many people including me will not open Microsoft Office documents as they can be security threats. Many people including me will not download attachments from this or other forums.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please include follow the instructions I gave to provide the log file. No other format is acceptable.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 21:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702355#M215113</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-29T21:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro and data step combination to read multiple text files as a string variable in a SAS datase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702361#M215115</link>
      <description>&lt;P&gt;FIL2READ is not part of the output dataset because you used as the variable named in the FILEVAR= option on the INFILE statement. If you want to save the value assign it to another variable that will be kept.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 23:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702361#M215115</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-29T23:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro and data step combination to read multiple text files as a string variable in a SAS datase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702362#M215116</link>
      <description>&lt;P&gt;The variable named as FILEVAR is not included in the output; you need to use another variable to which you assign the value from the FILEVAR= variable.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 23:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702362#M215116</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-29T23:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro and data step combination to read multiple text files as a string variable in a SAS datase</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702490#M215167</link>
      <description>Thanks, Kurt. Apologies, Paige that I could not figure out the SAS program / log combination to upload.</description>
      <pubDate>Mon, 30 Nov 2020 13:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-and-data-step-combination-to-read-multiple-text-files-as-a/m-p/702490#M215167</guid>
      <dc:creator>nirupmenon</dc:creator>
      <dc:date>2020-11-30T13:11:55Z</dc:date>
    </item>
  </channel>
</rss>

