<?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: blank line as delimiter in text file in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3067#M977</link>
    <description>Yes, I know that lg=1 because I hit the space bar one time. What I meant to write and didn't (since the mind-typing interface was broken) was that this person needs to do something similar to check their "blank" line to see whether it is one space or 10 spaces or whatever it is. Because he/she will have to change their conditional logic accordingly.&lt;BR /&gt;
cynthia&lt;BR /&gt;
ps....still hoping for the mind-SAS interface as well as the mind-typing interface.</description>
    <pubDate>Wed, 16 May 2007 02:19:51 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2007-05-16T02:19:51Z</dc:date>
    <item>
      <title>blank line as delimiter in text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3064#M974</link>
      <description>I'm trying to get sas to read an ascii text file with records of variable length separated by blank lines (1 blank line between each record). I simply want to create a 1-column dataset of all records. The problem is that each record consists of many lines broken by carriage returns. I have tried variations of the following to no avail:&lt;BR /&gt;
&lt;BR /&gt;
data raw;&lt;BR /&gt;
	infile 'c:\mydata.txt' truncover lrecl=99999 dlm='0D0D'X;&lt;BR /&gt;
	input raw $char9999.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Any ideas appreciated!</description>
      <pubDate>Tue, 15 May 2007 22:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3064#M974</guid>
      <dc:creator>leaving</dc:creator>
      <dc:date>2007-05-15T22:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: blank line as delimiter in text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3065#M975</link>
      <description>Hi!&lt;BR /&gt;
  I typed this data into Notepad, into a file called c:\temp\cr_blank.txt&lt;BR /&gt;
[pre]&lt;BR /&gt;
record 1 and even more stuff &lt;BR /&gt;
still record 1 &lt;BR /&gt;
and this is also record 1 &lt;BR /&gt;
 &lt;BR /&gt;
record2 record2 record2 &lt;BR /&gt;
more record2 &lt;BR /&gt;
guess what this is also record 2 &lt;BR /&gt;
and this too&lt;BR /&gt;
 &lt;BR /&gt;
just one line for record3&lt;BR /&gt;
 &lt;BR /&gt;
[/pre]&lt;BR /&gt;
 I made sure to put a carriage return at the end of every line and then put 1 hit of the space bar for my "blank" line separating each record.&lt;BR /&gt;
 &lt;BR /&gt;
Then, I used this program to read my file. You may have to change the logic a bit to read your file:&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
data readraw (keep=record_num cntlines wholerec);&lt;BR /&gt;
  length wholerec $1000 inline $256;&lt;BR /&gt;
  retain wholerec record_num cntlines;&lt;BR /&gt;
  infile 'c:\temp\cr_blank.txt' length=lg end=eof ;&lt;BR /&gt;
  input @1 inline $varying. lg;&lt;BR /&gt;
  put lg= _infile_ ;&lt;BR /&gt;
  if _n_ = 1 then do; &lt;BR /&gt;
     cntlines = 0; &lt;BR /&gt;
     record_num=1; &lt;BR /&gt;
  end;&lt;BR /&gt;
  if lg gt 1 then do;&lt;BR /&gt;
    cntlines + 1;&lt;BR /&gt;
    wholerec = trim(wholerec)||' '||trim(inline);&lt;BR /&gt;
  end;&lt;BR /&gt;
  if inline = ' ' or lg eq 1 or eof then do;&lt;BR /&gt;
    output;&lt;BR /&gt;
    wholerec = ' ';&lt;BR /&gt;
    record_num + 1;&lt;BR /&gt;
    cntlines = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                  &lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='c:\temp\readrec.html';&lt;BR /&gt;
proc print data=readraw;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
The key is knowing that $varying. is an INFORMAT that you can use to read variable length records. When you use the LENGTH= option on your INFILE statement, SAS makes a variable (in this case, LG) that contains the "length" of the current record in the input buffer. So I don't have to worry about variable length records, because $varying allows SAS to read each "line". When I did the "put lg= _infile_;" statement, this is what I got in the log:&lt;BR /&gt;
[pre]&lt;BR /&gt;
lg=29 record 1 and even more stuff&lt;BR /&gt;
lg=15 still record 1&lt;BR /&gt;
lg=26 and this is also record 1&lt;BR /&gt;
lg=1&lt;BR /&gt;
lg=24 record2 record2 record2&lt;BR /&gt;
lg=13 more record2&lt;BR /&gt;
lg=33 guess what this is also record 2&lt;BR /&gt;
lg=12 and this too&lt;BR /&gt;
lg=1&lt;BR /&gt;
lg=25 just one line for record3&lt;BR /&gt;
lg=1&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Notice how the "length" variable, LG, was 1 on every "blank" line that I had in my record. Even though I hit a Carriage Return (ENTER) key, I believe that it got translated to a space when SAS was reading the file or else it was treated as an "end of record" marker on my operating system (Windows).&lt;BR /&gt;
 &lt;BR /&gt;
You may have to fiddle with your LRECL= or the LENGTH statement for INLINE or WHOLEREC variables or with the logic of the code where the record is output, but I took a brute force approach and just concatenated every new "line" (represented by the INLINE variable) with the WHOLEREC variable and then only output the WHOLEREC variable with a "RECORD_NUM" variable and a CNTLINES variable -- CNTLINES represents the number of lines that went into making this new record. &lt;BR /&gt;
 &lt;BR /&gt;
There are probably some more elegant approaches, involving the use of the @@ to read the input or an explicit DO LOOP; however, I find that sometimes elegant code is harder to maintain and harder to explain.&lt;BR /&gt;
  &lt;BR /&gt;
If you try some variation of this technique and are still having problems, then your best bet is to contact Tech Support, because you could send them a copy of your input file on which they could test code. And they could collect any operating system information from you which may affect the kind of code that you need to write. To contact Tech Support, refer to: &lt;A href="http://support.sas.com/techsup/contact/index.html" target="_blank"&gt;http://support.sas.com/techsup/contact/index.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Good luck,&lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 15 May 2007 23:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3065#M975</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-05-15T23:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: blank line as delimiter in text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3066#M976</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
You got lg=1 on your blank lines because you hit a single space before hitting the enter key.&lt;BR /&gt;
&lt;BR /&gt;
"Leaving", be careful with '0D0D'x as a delimiter.  Different OS's use different ways to determine the end of a line.  That string would not appear in Windows, for instance, as it uses two characters to mark the end of a line (&lt;CR&gt;&lt;LF&gt;).&lt;BR /&gt;
&lt;BR /&gt;
Doc Muhlbaier&lt;BR /&gt;
Duke&lt;/LF&gt;&lt;/CR&gt;</description>
      <pubDate>Wed, 16 May 2007 01:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3066#M976</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2007-05-16T01:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: blank line as delimiter in text file</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3067#M977</link>
      <description>Yes, I know that lg=1 because I hit the space bar one time. What I meant to write and didn't (since the mind-typing interface was broken) was that this person needs to do something similar to check their "blank" line to see whether it is one space or 10 spaces or whatever it is. Because he/she will have to change their conditional logic accordingly.&lt;BR /&gt;
cynthia&lt;BR /&gt;
ps....still hoping for the mind-SAS interface as well as the mind-typing interface.</description>
      <pubDate>Wed, 16 May 2007 02:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/blank-line-as-delimiter-in-text-file/m-p/3067#M977</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-05-16T02:19:51Z</dc:date>
    </item>
  </channel>
</rss>

