<?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: Read multiple lines as part of a single record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317794#M69604</link>
    <description>&lt;P&gt;Once you got table WANT,it is easy for you to get final result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;(Edited)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 infile 'c:\temp\x.txt' length=len lrecl=32767;
 input x $varying32767. len;
 pid=prxparse('/^\d+\s+/');
 if prxmatch(pid,x) then group+1;
run;

data want;
length want $ 400;
 do i=1 by 1 until(last.group);
  set temp;
  by group;
  want=cats(want,x);
 end;
 keep want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Dec 2016 08:30:18 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-12-09T08:30:18Z</dc:date>
    <item>
      <title>Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317680#M69578</link>
      <description>&lt;P&gt;I have the following data in a tab delimited .dat file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; cord &amp;nbsp; BAD APPLES &amp;nbsp; bad apples are terrible for your health&lt;BR /&gt;2 &amp;nbsp; logo &amp;nbsp; BAD APPLES &amp;nbsp; bad apples are terrible for&lt;BR /&gt;your health&lt;BR /&gt;3 &amp;nbsp; cord &amp;nbsp; GOOD APPLES &amp;nbsp; bad apples are terrible for your health&lt;BR /&gt;4 &amp;nbsp; brat &amp;nbsp; &amp;nbsp;BAD APPLES &amp;nbsp; bad apples are terrible for&lt;BR /&gt;your health&lt;BR /&gt;5 &amp;nbsp; brat&amp;nbsp; &amp;nbsp; BAD APPLES &amp;nbsp; bad apples are terrible for your health&lt;BR /&gt;6 &amp;nbsp; cord &amp;nbsp; BAD MANGOES &amp;nbsp; bad apples are terrible for your health&lt;BR /&gt;7 &amp;nbsp; logo &amp;nbsp; BAD APPLES &amp;nbsp; bad apples are terrible for your health&lt;BR /&gt;8 &amp;nbsp; cord &amp;nbsp; BAD APPLES &amp;nbsp; bad apples are terrible for your health&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to read this data into SAS with the following variable names:&lt;BR /&gt;study_id type fruit_type description&lt;/P&gt;&lt;P&gt;Note that in some cases, an observation extends beyond on line (one record). The main problem i want to solve is how to tell SAS that when it encounters a point where the contents of the variable, "description" extends beyond one line, it should read the next line as part of the description variable.&lt;/P&gt;&lt;P&gt;I will highly appreciate a help on this.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 20:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317680#M69578</guid>
      <dc:creator>atijjani</dc:creator>
      <dc:date>2016-12-08T20:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317687#M69579</link>
      <description>&lt;P&gt;Are there actual line breaks such as carriage return or line feed such as from using an "Enter" key when typing? or is line just wrapping due to line length?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is this coming from Excel where people were entering data with&amp;nbsp; the Alt-Enter to make multiline entries?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any notable pattern involved?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 20:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317687#M69579</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-08T20:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317700#M69580</link>
      <description>&lt;P&gt;This is coming from a log file with no text wrapping. One notable pattern is that when ever the description field extends beyond one line, the next line starts with the string "PCP". The next line should have started with a number. So what SAS does everytime it encounter this line break is it sets the ID (which supposed to be a numerical variable to missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 21:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317700#M69580</guid>
      <dc:creator>atijjani</dc:creator>
      <dc:date>2016-12-08T21:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317794#M69604</link>
      <description>&lt;P&gt;Once you got table WANT,it is easy for you to get final result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;(Edited)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 infile 'c:\temp\x.txt' length=len lrecl=32767;
 input x $varying32767. len;
 pid=prxparse('/^\d+\s+/');
 if prxmatch(pid,x) then group+1;
run;

data want;
length want $ 400;
 do i=1 by 1 until(last.group);
  set temp;
  by group;
  want=cats(want,x);
 end;
 keep want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2016 08:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317794#M69604</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-09T08:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317830#M69609</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;input study_id$ type$ frut_type$ description &amp;amp;$ 100.;&lt;BR /&gt;datalines;&lt;BR /&gt;cord BAD APPLES bad apples are terrible for your health&lt;BR /&gt;logo BAD APPLES bad apples are terrible for your health&lt;BR /&gt;cord GOOD APPLES bad apples are terrible for your health&lt;BR /&gt;brat BAD APPLES bad apples are terrible for your health&lt;BR /&gt;brat BAD APPLES bad apples are terrible for your health&lt;BR /&gt;cord BAD MANGOES bad apples are terrible for your health&lt;BR /&gt;logo BAD APPLES bad apples are terrible for your health&lt;BR /&gt;cord BAD APPLES bad apples are terrible for your health&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 09:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317830#M69609</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2016-12-09T09:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317880#M69627</link>
      <description>&lt;P&gt;Thanks in the context of my data, what will the variables, cats, x, &amp;nbsp;and want be?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 12:37:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317880#M69627</guid>
      <dc:creator>atijjani</dc:creator>
      <dc:date>2016-12-09T12:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317890#M69630</link>
      <description>&lt;P&gt;Get it from varaible WANT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;study_id=scan(want,1,'09'x);&lt;/P&gt;
&lt;P&gt;fruit_type=scan(want,2,'09'x);&lt;/P&gt;
&lt;P&gt;..............&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 13:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317890#M69630</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-09T13:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317896#M69631</link>
      <description>&lt;P&gt;Another issue is that i dont understand what is the relationship between the data temp, want, and my data. How will i link them?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 13:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/317896#M69631</guid>
      <dc:creator>atijjani</dc:creator>
      <dc:date>2016-12-09T13:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/318041#M69650</link>
      <description>&lt;P&gt;The following should do the job. You will have to point your infile statement to your external file and use as delimiter a tab instead of a comma - but else the code should pretty much do the job as posted.&lt;/P&gt;
&lt;P&gt;I've used as test condition whether it's a new record of a flowover from the previous record, if there is a digit on position one of the record. You can of course also use some other test if that's not sufficient for your data (eg: is there a TAB in the input string?).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  infile datalines dlm=',' truncover;

  /* read a new line of data and map against variables */
  input @1 study_id type:$10. fruit_type:$20. description:$100.;

  /* read the next line of data. Hold the input pointer on the current line */
  input @@;

  /* test if new observation or flowover from previous record           */
  /* test condition: first non blank character in row is not a digit    */
  _test= notdigit(substrn(left(_infile_),1,1));

  /* if it's a flowover then concatenate the remainder string to the description variable */
  /*   and then set input pointer to next row of source data */
  if _test then
    do;
      description=catx(' ',description,_infile_);
      input;
    end;

  datalines;
1,cord,BAD APPLES,bad apples are terrible for your health
2,logo,BAD APPLES,bad apples are terrible for
your health
3,cord,GOOD APPLES,bad apples are terrible for your health
4,brat,BAD APPLES,bad apples are terrible for
your health
5,brat,BAD APPLES,bad apples are terrible for your health
6,cord,BAD MANGOES,bad apples are terrible for your health
7,logo,BAD APPLES,bad apples are terrible for your health
8,cord,BAD APPLES,bad apples are terrible for your health
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;input&amp;nbsp;@@;&lt;/P&gt;
&lt;P&gt;1. Read a new line of data into the input buffer&lt;/P&gt;
&lt;P&gt;2. _infile_ that's an automatic variable which gives us access to the input buffer&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp;@@ holds the input pointer on the current line even over the iteration of a data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - gets only released by another input statement. That's why this empty input statement is required if the test is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n0oaql83drile0n141pdacojq97s.htm&amp;nbsp;" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n0oaql83drile0n141pdacojq97s.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Dec 2016 02:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/318041#M69650</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-10T02:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read multiple lines as part of a single record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/318069#M69657</link>
      <description>&lt;PRE&gt;

TEMP contain the data from your txt file and make a group variable.

WANT is aligning these wrong rows and get the final result you need.
&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Dec 2016 10:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-multiple-lines-as-part-of-a-single-record/m-p/318069#M69657</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-10T10:44:06Z</dc:date>
    </item>
  </channel>
</rss>

