<?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: Proc Transpose Non-Systematic Data in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815553#M81832</link>
    <description>&lt;P&gt;Seems pretty simple as the structure looks very regular (systematic actually).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just keep reading comment lines until you hit an empty line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile have truncover end=eof;
  length id 8 start end $12 nrows 8 comment $300 ;
  input id / (start 2*end) (:) / ;
  do nrows=1 by 1 until(_infile_=' ' or eof);
    comment=catx('|',comment,_infile_);
    input;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nocenter ls=132 ps=60;

proc report data=want split='|' headline;
  column id start end nrows comment;
  define comment / width=80 flow;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1653756272160.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71840iBEE0E48FB5C90485/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1653756272160.png" alt="Tom_0-1653756272160.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 28 May 2022 18:49:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-05-28T18:49:12Z</dc:date>
    <item>
      <title>Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815541#M81829</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I have a subtitle file, which I want to convert into data:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JAR_1-1653749336257.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71836i57BB7858A19E6AB0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JAR_1-1653749336257.png" alt="JAR_1-1653749336257.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JAR_2-1653749382904.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71837i5852C7EA1BD2849E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JAR_2-1653749382904.png" alt="JAR_2-1653749382904.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As few entries have multiple lines, I seek some help.&amp;nbsp;&lt;BR /&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Jijil Ramakrishnan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 May 2022 14:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815541#M81829</guid>
      <dc:creator>JAR</dc:creator>
      <dc:date>2022-05-28T14:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815548#M81830</link>
      <description>&lt;P&gt;First a comment about your Want data set? You really do want to repeat the Index, and likely the start and end time values on each observation after reading the data. Otherwise any SORT is going to leave the text "orphaned" from the proper information about index for any of the multiple line bits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The below example has had the , in the time values changed to . as I am not going to mess with my system settings to deal with foreign language conventions. The code should work with your data pointing to your text file with an infile statement. Or copy some of your example text and replace the datalines I used for testing.&lt;/P&gt;
&lt;PRE&gt;data example;
  informat index 8. starttime endtime time15. text $100.;
  format starttime endtime time12.3;
  retain index starttime endtime;
  input @;
  if input(_infile_,?? 8.) then do;     
      index =input(_infile_,8.);
      input;
      input starttime text endtime;
      input ;
      text=_infile_;
      output;
  end;
  else if anyalpha(_infile_) then do;
      text=_infile_;
      output;
      input;
  end;
  else input;

datalines;
1
00:00:49.260 --&amp;gt; 00:00:50.327
Gerald Tate's here.

2
00:00:50.395 --&amp;gt; 00:00:51.729
He wants to know         
what's happening to his deal.

3
00:00:51.797 --&amp;gt; 00:00:53.264
Go get Harvey.

4
00:00:54.793 --&amp;gt; 00:00:58.793
== sync, corrected by &amp;lt;font color="#00ff00"&amp;gt;elderman&amp;lt;/font&amp;gt; ==
;

&lt;/PRE&gt;
&lt;P&gt;If you haven't used the trailing @ on input it holds the input buffer so it can be examined in the SAS automatic variable _infile_. So the code checks to see if a line is a valid number and if so assumes that is the index value, then reads the time values. Reuse of the TEXT variable to read the --&amp;gt; instead of dealing with fancier parsing of that line. Also assumes one line of text.&lt;/P&gt;
&lt;P&gt;The check for the number value using the input function includes the ?? to suppress invalid data messages that would occur with the second text line in those sets such as on index=2.&lt;/P&gt;</description>
      <pubDate>Sat, 28 May 2022 16:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815548#M81830</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-28T16:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815551#M81831</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;You are right, the Index must increment for every line of text.&amp;nbsp;&lt;BR /&gt;How can I change the "2" into "3".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JAR_0-1653755178231.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71839i550B523FEF18ADB1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JAR_0-1653755178231.png" alt="JAR_0-1653755178231.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Please advise (or correct the code).&amp;nbsp;&lt;BR /&gt;Thank you!&lt;BR /&gt;Jijil&lt;/P&gt;</description>
      <pubDate>Sat, 28 May 2022 16:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815551#M81831</guid>
      <dc:creator>JAR</dc:creator>
      <dc:date>2022-05-28T16:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815553#M81832</link>
      <description>&lt;P&gt;Seems pretty simple as the structure looks very regular (systematic actually).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just keep reading comment lines until you hit an empty line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile have truncover end=eof;
  length id 8 start end $12 nrows 8 comment $300 ;
  input id / (start 2*end) (:) / ;
  do nrows=1 by 1 until(_infile_=' ' or eof);
    comment=catx('|',comment,_infile_);
    input;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nocenter ls=132 ps=60;

proc report data=want split='|' headline;
  column id start end nrows comment;
  define comment / width=80 flow;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1653756272160.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71840iBEE0E48FB5C90485/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1653756272160.png" alt="Tom_0-1653756272160.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 May 2022 18:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815553#M81832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-28T18:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815565#M81837</link>
      <description>&lt;P&gt;I would say that you do NOT want change that "Index". Why? The second or other subsequent lines of text belong in the same "group".&lt;/P&gt;
&lt;P&gt;This might be one of the times where combining different records so all that text is a single value make sense.&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 01:18:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815565#M81837</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-29T01:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815576#M81840</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile "c:\temp\subtitle.txt" encoding='utf-8' termstr=crlf length=len;
input temp $varying200. len;
if missing(temp) then do;group+1;delete;end;
run;

data have2;
 set have;
 by group;
 if first.group then n=0;
 n+1;
 if n&amp;gt;2 then n=3;
run;

data have3;
do until(last.n);
 set have2;
 by group n;
 length want $ 200;
 want=catx(' ',want,temp);
end;
drop temp;
run;

proc transpose data=have3 out=have4 prefix=var;
by group;
id n;
var want;
run;

data want;
 set have4(rename=(var1=index var3=text));
 start_time=scan(var2,1,'-&amp;gt; ');
 end_time=scan(var2,-1,'-&amp;gt; ');
 drop group _name_ var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 May 2022 10:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/815576#M81840</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-05-29T10:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816137#M81854</link>
      <description>Thank you! This is so concise and efficient!</description>
      <pubDate>Thu, 02 Jun 2022 05:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816137#M81854</guid>
      <dc:creator>JAR</dc:creator>
      <dc:date>2022-06-02T05:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816138#M81855</link>
      <description>&lt;P&gt;Thank you KShap!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 05:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816138#M81855</guid>
      <dc:creator>JAR</dc:creator>
      <dc:date>2022-06-02T05:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816139#M81856</link>
      <description>&lt;P&gt;True!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 05:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816139#M81856</guid>
      <dc:creator>JAR</dc:creator>
      <dc:date>2022-06-02T05:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816160#M81858</link>
      <description>&lt;P&gt;Sorry. Tom,&lt;/P&gt;
&lt;P&gt;I have to say Tom's code lost the last record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1654156203938.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71964i91B58FE47B3BAB36/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1654156203938.png" alt="Ksharp_0-1654156203938.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 07:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816160#M81858</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-02T07:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Transpose Non-Systematic Data</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816196#M81859</link>
      <description>&lt;P&gt;That just needs a trivial change avoid reading past the end of the file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile have truncover end=eof;
  length id 8 start end $12 nrows 8 comment $300 ;
  input id / (start 2*end) (:) ;
  if eof then _infile_=' ';
  else input ;
  do nrows=1 by 1 while(_infile_ ne ' ');
    comment=catx('|',comment,_infile_);
    if eof then _infile_=' ';
    else input;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jun 2022 14:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Transpose-Non-Systematic-Data/m-p/816196#M81859</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-02T14:26:19Z</dc:date>
    </item>
  </channel>
</rss>

