<?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 can I read a file's entire contents without knowing its format? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150927#M39741</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this perhaps?&lt;/P&gt;&lt;PRE&gt;/* Create a text file */
data _null_ ;
&amp;nbsp;&amp;nbsp;&amp;nbsp; file "s:\workshop\test.txt";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.class;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put _all_;
run;

/*Read the whole text file into a text variable *
data test;
&amp;nbsp;&amp;nbsp; length text $32767;
&amp;nbsp;&amp;nbsp; retain text '';
&amp;nbsp;&amp;nbsp; infile "s:\workshop\test.txt" flowover dlmstr='//' end=last;
&amp;nbsp;&amp;nbsp; input;
&amp;nbsp;&amp;nbsp; text=cats(text,_infile_);
&amp;nbsp;&amp;nbsp; if last then output;
run;
proc print; run;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 May 2014 18:04:35 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2014-05-08T18:04:35Z</dc:date>
    <item>
      <title>How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150925#M39739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming I have a plain-text file with contents in an unknown or inconsistent format:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Could be spread over multiple lines, or not&lt;/LI&gt;&lt;LI&gt;Could have commas, or not&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;How would I go about reading it into a single variable of a single observation? I just want a "text" variable to contain the entire contents.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Try as I might I can't write a program which will get me what I want - I hope that I'm missing something very simple.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Example text file:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;[{"var1":"ses-&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;14_14723","var2":652720,"var3":653940}]&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;My SAS code so far. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;data work.test;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile "C:\test.txt" flowover dlmstr="&amp;amp;(*&amp;amp;)(*&amp;amp;";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input alltext :$ 3000.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;As you can see - &lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I've experimented using flowover to search for data on new lines. &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I'm using a delimiter string with a ridiculous value I'll never hit so that the third line isn't split, and &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;I've chosen a randomly-high length for the alltext variable, but used the colon to tell the input statement the length could be variable&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;This strikes me as really hacky and I'm sure it can't be right. It also returns me 2 observations - one for line 1, and one for line 3.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Any help would be much appreciated.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2014 16:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150925#M39739</guid>
      <dc:creator>GrokAndRoll</dc:creator>
      <dc:date>2014-05-08T16:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150926#M39740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well I hope you are aware what you are asking. Not knowing the format, is it video/audio and you want to build your own codecs?&lt;/P&gt;&lt;P&gt;Let me assume you are at least expecting character data in some encoding like Unicode and you are knowing just that type.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n1rill4udj0tfun1fvce3j401plo.htm" title="http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n1rill4udj0tfun1fvce3j401plo.htm"&gt;SAS(R) 9.3 Statements: Reference&lt;/A&gt; (infile)&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/hostwin/63047/HTML/default/viewer.htm#chifoptfmain.htm" title="http://support.sas.com/documentation/cdl/en/hostwin/63047/HTML/default/viewer.htm#chifoptfmain.htm"&gt;SAS(R) 9.3 Companion for Windows&lt;/A&gt; (infile)&lt;/P&gt;&lt;P&gt;There is a limit that string variables cannot be longer as 32Kb.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can read the fie in binary format using:&amp;nbsp; &lt;/P&gt;&lt;P&gt;Recfm=N and than choose your char variables into splitting as an array (maximum size?) or as observations using reading in logicl blocks (reclen) of eg 32Kb.&lt;/P&gt;&lt;P&gt;The automatic _infile_ variable can be uses as the source after each "input ;" statement. An input statement not reading any variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have a format using a record-layout (what is the maximum length)? You can use those record indicators.&lt;/P&gt;&lt;P&gt;These are the CR LF CRLF characters giving a basic format to the file.&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2014 17:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150926#M39740</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-05-08T17:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150927#M39741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like this perhaps?&lt;/P&gt;&lt;PRE&gt;/* Create a text file */
data _null_ ;
&amp;nbsp;&amp;nbsp;&amp;nbsp; file "s:\workshop\test.txt";
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.class;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put _all_;
run;

/*Read the whole text file into a text variable *
data test;
&amp;nbsp;&amp;nbsp; length text $32767;
&amp;nbsp;&amp;nbsp; retain text '';
&amp;nbsp;&amp;nbsp; infile "s:\workshop\test.txt" flowover dlmstr='//' end=last;
&amp;nbsp;&amp;nbsp; input;
&amp;nbsp;&amp;nbsp; text=cats(text,_infile_);
&amp;nbsp;&amp;nbsp; if last then output;
run;
proc print; run;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2014 18:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150927#M39741</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2014-05-08T18:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150928#M39742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 May 2014 23:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150928#M39742</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-05-08T23:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150929#M39743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom - Partly to see if it's possible. The other reason was that I am writing a piece of SAS code to parse a JSON response, but my parser assumes that everything is on the same line. Turned out there were a couple of random new lines in there so I wanted to load up the file and prepare it for use by removing all new lines. I hoped there would be a way of loading all contents in one variable, running a tranwrd or compress function against it, and voila.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I realise the answer is probably "Don't do that" but I was curious.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 May 2014 08:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150929#M39743</guid>
      <dc:creator>GrokAndRoll</dc:creator>
      <dc:date>2014-05-09T08:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150930#M39744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SASJedi (if that is your real name :smileysilly:) - Thanks, that does the job perfectly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of course I concede I probably shouldn't be taking this approach, but it's interesting to know how it could be done. I must have read about the _infile_ variable in the past, but had forgotten it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 May 2014 08:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150930#M39744</guid>
      <dc:creator>GrokAndRoll</dc:creator>
      <dc:date>2014-05-09T08:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I read a file's entire contents without knowing its format?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150931#M39745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Grokandroll, SASjedi is of course Mark Jordan &lt;A href="http://blogs.sas.com/content/sastraining/?s=sasjedi"&gt;http://blogs.sas.com/content/sastraining/?s=sasjedi&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Creating json: &lt;A href="http://support.sas.com/documentation/cdl/en/proc/66663/HTML/default/viewer.htm#p0u973c951w3y4n1xw90j3iglj42.htm" title="http://support.sas.com/documentation/cdl/en/proc/66663/HTML/default/viewer.htm#p0u973c951w3y4n1xw90j3iglj42.htm"&gt;Base SAS(R) 9.4 Procedures Guide, Second Edition&lt;/A&gt; (proc json) &lt;/P&gt;&lt;P&gt;The json data processing is a possible enhancement as alternative for XML.&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings13/296-2013.pdf" title="http://support.sas.com/resources/papers/proceedings13/296-2013.pdf"&gt;http://support.sas.com/resources/papers/proceedings13/296-2013.pdf&lt;/A&gt; is some same approach as you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 May 2014 08:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-read-a-file-s-entire-contents-without-knowing-its/m-p/150931#M39745</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-05-09T08:31:32Z</dc:date>
    </item>
  </channel>
</rss>

