<?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 file (w/ non-consistent data) into long format in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168199#M43543</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just one datastep needed. See commentlines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt;data long&lt;/SPAN&gt; (keep=id sex time intensity) ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; length sex $ 1 ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; array timen(5) timen1-timen5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; array inten(5) intensity1-intensity5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; infile cards missover DSD DLM=',';&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #339966;"&gt;/*just to be sure of options */&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff; font-family: courier new,courier;"&gt; input id sex @ ; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; isize=(countw(_infile_)-2)/2 ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #339966;"&gt;/* _infile is the current record - size of the array in words*/&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt; do&lt;/SPAN&gt; i=1 to isize ; &lt;SPAN style="color: #0000ff;"&gt;input timen&lt;I&gt; @; end; &lt;/I&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt; do&lt;/SPAN&gt; i=1 to isize ; &lt;SPAN style="color: #0000ff;"&gt;input inten&lt;I&gt; @; end; &lt;/I&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; put id sex isize ; &lt;SPAN style="color: #339966;"&gt;/* debugging shows processing */&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt;do&lt;/SPAN&gt; i=1 to isize ; &lt;SPAN style="color: #339966;"&gt;/* output long in array size */&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; time=timen&lt;I&gt; ; &lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; intensity=inten&lt;I&gt; ; &lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; output ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff; font-family: courier new,courier;"&gt; end; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;datalines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;1,m,1,45,5,2,5,3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;2,m,3,6,5,5,6,3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;3,m,6,65,5,2,20,3,23,63&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;4,m,9,6,5,43,5,3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;5,m,3,195,5,2,5,32,34,78,12,42&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;6,m,6,92,5,232,5,23&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff; font-family: courier new,courier;"&gt; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Aug 2014 10:13:35 GMT</pubDate>
    <dc:creator>jakarman</dc:creator>
    <dc:date>2014-08-20T10:13:35Z</dc:date>
    <item>
      <title>reading file (w/ non-consistent data) into long format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168197#M43541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having trouble reading a file containing non-consistent data in wide format into long format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example, the data looks like this:&lt;/P&gt;&lt;P&gt;subject, sex, time1, time2, time3,..., intensity1, intensity2, intensity3....&lt;/P&gt;&lt;P&gt;1,m,1,45,5,2,5,3&lt;/P&gt;&lt;P&gt;2,m,3,6,5,5,6,3&lt;/P&gt;&lt;P&gt;3,m,6,65,5,2,20,3,23,63&lt;/P&gt;&lt;P&gt;4,m,9,6,5,43,5,3&lt;/P&gt;&lt;P&gt;5,m,3,195,5,2,5,32,34,78,12,42&lt;/P&gt;&lt;P&gt;6,m,6,92,5,232,5,23&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so some subjects may have 3 times and 3 intensities and other may have 4 times/intensities or 5 times/intensities...&lt;/P&gt;&lt;P&gt;If I read the file as&lt;/P&gt;&lt;P&gt;data id sex$ time1-5, intensity1-5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then transform into long format by&lt;/P&gt;&lt;P&gt;data long; set wide;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array t(5) time1-time5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array i(5) intensity1-intensity5;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to 5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time=t(j);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intensity= i(j);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&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;however for those subjects that have &amp;lt;5 times/intensities, SAS will continue to read the next subject's data and the whole table screws up.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is there a way I can read the data directly into long format? something like...&lt;/P&gt;&lt;P&gt;data long;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; infle 'xxx';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input id sex$ @@;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - do a loop that reads the remaining variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - I can change the variables into time1 intensity1 time2 intensity2 time3 intensity3....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time=&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intensity=&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for any suggestions!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ming&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Aug 2014 22:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168197#M43541</guid>
      <dc:creator>Ming</dc:creator>
      <dc:date>2014-08-19T22:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: reading file (w/ non-consistent data) into long format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168198#M43542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first data step determines the number of the variables (times / intensity) which the data set will contain,&lt;/P&gt;&lt;P&gt;while the second step imports the values within the data set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;input @5 tmins &amp;amp; $30.;&lt;BR /&gt;x=(length(strip(compress(tmins,,'d')))+1)/2;&lt;BR /&gt;if _N_=1 then call symputx('nrvar',x);&lt;BR /&gt;else if x gt input(symget('nrvar'),best12.) then call symputx('nrvar',x);;&lt;BR /&gt;datalines;&lt;BR /&gt;1,m,1,45,5,2,5,3&lt;BR /&gt;2,m,3,6,5,5,6,3&lt;BR /&gt;3,m,6,65,5,2,20,3,23,63&lt;BR /&gt;4,m,9,6,5,43,5,3&lt;BR /&gt;5,m,3,195,5,2,5,32,34,78,12,42&lt;BR /&gt;6,m,6,92,5,232,5,23&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have (drop=rowvar i tmins);&lt;BR /&gt;infile datalines dsd;&lt;BR /&gt;*VARIABLES;&lt;BR /&gt;input subject sex $ tmins &amp;amp; $30. @ ;&lt;BR /&gt;array times{&amp;amp;nrvar};&lt;BR /&gt;array intens{&amp;amp;nrvar};&lt;BR /&gt;*Computation;&lt;BR /&gt;rowvar=length(strip(compress(tmins,,'d')))+1;*number of commas in order to determin the loop;&lt;BR /&gt;do i=1 to rowvar/2;&lt;BR /&gt; times{i}=input(scan(tmins,i,","),best12.);*in order to avoid the note within the log;&lt;BR /&gt; intens{i}=input(scan(tmins,i+rowvar/2,","),best12.);&lt;BR /&gt;end; &lt;BR /&gt;datalines;&lt;BR /&gt;1,m,1,45,5,2,5,3&lt;BR /&gt;2,m,3,6,5,5,6,3&lt;BR /&gt;3,m,6,65,5,2,20,3,23,63&lt;BR /&gt;4,m,9,6,5,43,5,3&lt;BR /&gt;5,m,3,195,5,2,5,32,34,78,12,42&lt;BR /&gt;6,m,6,92,5,232,5,23&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 08:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168198#M43542</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-08-20T08:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: reading file (w/ non-consistent data) into long format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168199#M43543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just one datastep needed. See commentlines&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt;data long&lt;/SPAN&gt; (keep=id sex time intensity) ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; length sex $ 1 ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; array timen(5) timen1-timen5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; array inten(5) intensity1-intensity5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; infile cards missover DSD DLM=',';&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #339966;"&gt;/*just to be sure of options */&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff; font-family: courier new,courier;"&gt; input id sex @ ; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; isize=(countw(_infile_)-2)/2 ;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #339966;"&gt;/* _infile is the current record - size of the array in words*/&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt; do&lt;/SPAN&gt; i=1 to isize ; &lt;SPAN style="color: #0000ff;"&gt;input timen&lt;I&gt; @; end; &lt;/I&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt; do&lt;/SPAN&gt; i=1 to isize ; &lt;SPAN style="color: #0000ff;"&gt;input inten&lt;I&gt; @; end; &lt;/I&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; put id sex isize ; &lt;SPAN style="color: #339966;"&gt;/* debugging shows processing */&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;SPAN style="color: #0000ff;"&gt;do&lt;/SPAN&gt; i=1 to isize ; &lt;SPAN style="color: #339966;"&gt;/* output long in array size */&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; time=timen&lt;I&gt; ; &lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; intensity=inten&lt;I&gt; ; &lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; output ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #3366ff; font-family: courier new,courier;"&gt; end; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;datalines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;1,m,1,45,5,2,5,3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;2,m,3,6,5,5,6,3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;3,m,6,65,5,2,20,3,23,63&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;4,m,9,6,5,43,5,3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;5,m,3,195,5,2,5,32,34,78,12,42&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;6,m,6,92,5,232,5,23&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff; font-family: courier new,courier;"&gt; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 10:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168199#M43543</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-20T10:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: reading file (w/ non-consistent data) into long format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168200#M43544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming that there are no missing values for "time" (=2 consecutive commas) below code should work - else it would need a little tweak. It's a variation of what &lt;A __default_attr="8872" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt; already posted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sample(drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; attrib id informat=$10. sex informat=$1.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array _t_i (20) 8.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call missing(of _all_);&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover dsd dlm=',';&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id sex _t_i&lt;LI&gt;;&amp;nbsp; &lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _isize=countc(_infile_,',')-1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _ind=1 to _isize by 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time=_t_i(_ind);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intensity=_t_i(_ind+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;1,m,1,45,5,2,5,3&lt;/P&gt;&lt;P&gt;2,m,3,6,5,5,6,3&lt;/P&gt;&lt;P&gt;3,m,6,65,5,2,20,3,23,63&lt;/P&gt;&lt;P&gt;4,m,9,6,5,43,5,3&lt;/P&gt;&lt;P&gt;5,m,3,195,5,2,5,32,34,78,12,42&lt;/P&gt;&lt;P&gt;6,m,6,92,5,232,5,23&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Patrick Matter&#xD;
&#xD;
Stole the "isize" approach from Jaap, so now the code should also work for cases where there is a missing (=2 consecutive commas)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 12:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168200#M43544</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-08-20T12:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: reading file (w/ non-consistent data) into long format</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168201#M43545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data sample(drop=n i);
infile cards;
input;
subject=scan(_infile_,1,',','m');
sex=scan(_infile_,2,',','m');
n=divide(countc(_infile_,',')-1,2);
do i=3 to n+2;
 time=scan(_infile_,i,',','m');
 intensity=scan(_infile_,i+n,',','m');
 output;
end;
datalines;
1,m,1,45,5,2,5,3
2,m,3,6,5,5,6,3
3,m,6,65,5,2,20,3,23,63
4,m,9,6,5,43,5,3
5,m,3,195,5,2,5,32,34,78,12,42
6,m,6,92,5,232,5,23
;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 14:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/reading-file-w-non-consistent-data-into-long-format/m-p/168201#M43545</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-20T14:16:44Z</dc:date>
    </item>
  </channel>
</rss>

