<?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: Reading data contained in multiple lines from text file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257996#M49611</link>
    <description>&lt;P&gt;Why should it be in a single data step instead taking advantage of PROC TRANSPOSE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do the same thing in a data step, but it takes a lot more code. &amp;nbsp;You will however get more control over the definition of the individual variables.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2016 16:17:13 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-03-21T16:17:13Z</dc:date>
    <item>
      <title>Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257984#M49606</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INPUT;
infile DATALINES DLM="|" missover;
DATALINES;
Name|Vidhya
Phone1|123456
Phone2|987655
Name|Shree
Phone1|345678
Name|Jagan
Phone1|5435678
Phone2|5431232
Name|Sharma
Phone1|8934751
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;looking for output&amp;nbsp;&lt;/P&gt;
&lt;P&gt;name|phone1|phone2&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 15:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257984#M49606</guid>
      <dc:creator>SJN</dc:creator>
      <dc:date>2016-03-21T15:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257994#M49609</link>
      <description>&lt;P&gt;In general read it in as NAME/VALUE pairs and use PROC TRANSPOSE to convert from multiple rows to multiple columns.&lt;/P&gt;
&lt;P&gt;You will want to generate a new variable to identify which blocks of rows in the original are to be grouped together into a new row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall ;
  infile DATALINES DLM="|" DSD TRUNCOVER ;
  length name $32 value $200 ;
  input name value;
  if upcase(name)='NAME' then id+1;
DATALINES;
Name|Vidhya
Phone1|123456
Phone2|987655
Name|Shree
Phone1|345678
Name|Jagan
Phone1|5435678
Phone2|5431232
Name|Sharma
Phone1|8934751
;
run;
proc transpose data=tall out=want (drop=_:) ;
  by id;
  id name;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257994#M49609</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-03-21T16:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257995#M49610</link>
      <description>&lt;P&gt;Thank you for your reply. I'm intrested in&amp;nbsp;datastep method.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257995#M49610</guid>
      <dc:creator>SJN</dc:creator>
      <dc:date>2016-03-21T16:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257996#M49611</link>
      <description>&lt;P&gt;Why should it be in a single data step instead taking advantage of PROC TRANSPOSE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do the same thing in a data step, but it takes a lot more code. &amp;nbsp;You will however get more control over the definition of the individual variables.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/257996#M49611</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-03-21T16:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/258000#M49613</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/57222"&gt;@SJN﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could replace the PROC TRANSPOSE step by the following data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
array var $200 name phone1 phone2;
do until(last.id);
  set tall(drop=name); /* or rename NAME to _NAME if you want to check its values instead of relying on counter I */
  by id;
  i=sum(i,1);
  var[i]=value;
end;
drop i: v:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that PROC TRANSPOSE, unlike the data step, would handle the case of more than two phone numbers without any change.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/258000#M49613</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-21T16:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/258019#M49617</link>
      <description>&lt;P&gt;A DATA step approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile datalines dlm="|" missover end=done;&lt;/P&gt;
&lt;P&gt;length name $ 20 phone1 phone2 $ 15;&lt;/P&gt;
&lt;P&gt;retain name phone1 phone2;&lt;/P&gt;
&lt;P&gt;input identifier $ @;&lt;/P&gt;
&lt;P&gt;if identifier = 'Name' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if _n_ &amp;gt; 1 then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; input name;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; phone1=' ';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; phone2=' ';&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if identifier = 'Phone1' then input phone1;&lt;/P&gt;
&lt;P&gt;else if identifier = 'Phone2' then input phone2;&lt;/P&gt;
&lt;P&gt;if done then output;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's untested.&amp;nbsp; The only piece I'm not sure about is whether END= works in combination with DATALINES but it should otherwise be OK.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/258019#M49617</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-21T16:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reading data contained in multiple lines from text file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/258038#M49626</link>
      <description>&lt;P&gt;Great, so everything is in one data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;END= does not work with DATALINES (I&amp;nbsp;wasn't sure either), but EOF= can be used instead. The latter requires a statement label, though. Hence, the line "&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;if done then output;&lt;/FONT&gt;" could be replaced by&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;return;
done: output;
drop identifier;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;to make it work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 17:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-data-contained-in-multiple-lines-from-text-file/m-p/258038#M49626</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-21T17:58:09Z</dc:date>
    </item>
  </channel>
</rss>

