<?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: Can I use arrays to capture &amp;quot;length&amp;quot; of multiple sequences of variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447574#M112470</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196763"&gt;@mariusmorthorst&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear All&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm using SAS university edition. I'll outline my problem by first outlining my data. &amp;nbsp;I've used the array command to create a variable for each week (in 2008)&amp;nbsp;displaying whether an observation lives in place A or B.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm wondering whether it's possible, using the array command, to&amp;nbsp;create new variables for each sequence respectively and in that variable for the specific sequence report the length of the sequence. &amp;nbsp;In the example above there would at most be 3 new variables (lets call them sequence1, sequence2 and sequence3). For the first observation sequence1 = 2, sequence2 = 3 and sequence3= 2. For the second observation&amp;nbsp;&amp;nbsp;sequence1 = 8, sequence2 = 0 and sequence3= 0.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What rule assigns values to those sequence variables? It isn't obvious to me. Why is sequence 3=2 for the first record, I might think&amp;nbsp;3 was more appropriate for the shown data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And with SAS 9.4 I get an error from spell(I).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are counting sequential recurrence of the same value are you allowing for up to 52 sequence variables? (Assuming that you only have 52 weeks (365 or 366&amp;nbsp;days in a year yields 52 and a fraction weeks so 53 may be needed).&lt;/P&gt;</description>
    <pubDate>Wed, 21 Mar 2018 20:29:06 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-03-21T20:29:06Z</dc:date>
    <item>
      <title>Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447556#M112462</link>
      <description>&lt;P&gt;Dear All&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm using SAS university edition. I'll outline my problem by first outlining my data. &amp;nbsp;I've used the array command to create a variable for each week (in 2008)&amp;nbsp;displaying whether an observation lives in place A or B.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;As my dataset is confidentiel I've created a quick look-a-like-version here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you see from the picture each observation can possibly move back and forth.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Skærmbillede 2018-03-21 20.29.31.png" style="width: 597px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19370iA370DFC507CC6F2D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Skærmbillede 2018-03-21 20.29.31.png" alt="Skærmbillede 2018-03-21 20.29.31.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I'm wondering whether it's possible, using the array command, to&amp;nbsp;create new variables for each sequence respectively and in that variable for the specific sequence report the length of the sequence. &amp;nbsp;In the example above there would at most be 3 new variables (lets call them sequence1, sequence2 and sequence3). For the first observation sequence1 = 2, sequence2 = 3 and sequence3= 2. For the second observation&amp;nbsp;&amp;nbsp;sequence1 = 8, sequence2 = 0 and sequence3= 0.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So far i've only succeed in capturing the length of the first sequence by the following code&lt;BR /&gt;&lt;BR /&gt;data newdata (compress=binary);&lt;BR /&gt;set olddata;&lt;BR /&gt;array weeks&amp;nbsp;(52) $2;&lt;BR /&gt;&lt;BR /&gt;endB=.;&lt;BR /&gt;periodB=.;&lt;BR /&gt;&lt;BR /&gt;if indicatorB = 1 then /* where indicatorB shows whether or not B is present within any of the weeks variables */&lt;BR /&gt;do i=startB to 52 by 1 UNTIL(spell(i) ne 'B'); /* where startB is a variable telling me in what week we first observe B (between 1-52) */&lt;BR /&gt;if weeks(i) in ('B') then endB = i;&lt;BR /&gt;end;&lt;BR /&gt;periodB=endB-startB+1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Hope you can help me update my code so &amp;nbsp;I can capture the different lengths of multiple sequences&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Kind regards&lt;BR /&gt;&lt;BR /&gt;Marius&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447556#M112462</guid>
      <dc:creator>mariusmorthorst</dc:creator>
      <dc:date>2018-03-21T20:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447560#M112464</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196763"&gt;@mariusmorthorst&lt;/a&gt;&amp;nbsp; Good afternoon, If you could post the sample of what you HAVE and what you WANT as &lt;STRONG&gt;&lt;EM&gt;plain&amp;nbsp;text&lt;/EM&gt;&lt;/STRONG&gt;, a lazy person like me would be interested to copy paste the data on to my sas software and do some program/testing. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447560#M112464</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-21T20:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447567#M112466</link>
      <description>&lt;P&gt;I would recommend transposing your data to a long format, then the problem is trivial.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;use the approach outlined here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With the modification of the NOTSORTED option on your BY statement so that the order is correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by id week value NOTSORTED;

if first.value then seq+1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can easily do this with arrays as well, but it's harder because you'll have to account for almost all weeks, so you can create seq1-seq8 to hold the values&amp;nbsp;but I see issues with using this later on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested because no data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
array week(8) week1-week8;
array seq(8);

index=1;
do i=2 to dim(week);
if week(i)=week(i-1) then seq(index)=seq(index)+1;
else do;
index+1;
seq(index) = 1;
end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447567#M112466</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T20:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447569#M112467</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks for your quick reply&lt;BR /&gt;&lt;BR /&gt;Is the following sufficient&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;What i have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;week 1&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week 2&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week 3&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week 4&lt;/TD&gt;&lt;TD&gt;week 5&lt;/TD&gt;&lt;TD&gt;week 6&lt;/TD&gt;&lt;TD&gt;week 7&lt;/TD&gt;&lt;TD&gt;week 8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;What i want&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;week 1&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week 2&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week 3&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;week 4&lt;/TD&gt;&lt;TD&gt;week 5&lt;/TD&gt;&lt;TD&gt;week 6&lt;/TD&gt;&lt;TD&gt;week 7&lt;/TD&gt;&lt;TD&gt;week 8&lt;/TD&gt;&lt;TD&gt;sequence1&lt;/TD&gt;&lt;TD&gt;sequence2&lt;/TD&gt;&lt;TD&gt;sequence3&lt;/TD&gt;&lt;TD&gt;number of sequence&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447569#M112467</guid>
      <dc:creator>mariusmorthorst</dc:creator>
      <dc:date>2018-03-21T20:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447570#M112468</link>
      <description>&lt;P&gt;This is very easy to do with SAS once your data is formatted properly. The proper format is long as opposed to wide, with&amp;nbsp;columns &lt;EM&gt;ID&lt;/EM&gt;, &lt;EM&gt;Week&lt;/EM&gt;, and&amp;nbsp;&lt;EM&gt;Place&lt;/EM&gt;. With that format the sequence lengths will be given by :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by ID week; run;

data want;
do seqLength = 1 by 1 until(last.place);
    set have; by id place notsorted;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447570#M112468</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-21T20:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447573#M112469</link>
      <description>&lt;P&gt;How many sequences do you want?&amp;nbsp; All?&amp;nbsp; Just the first 3?&amp;nbsp; It's possible that the number ranges from 1 to 52 for one ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't sequence3 equal 3 (not 2) for the first ID?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447573#M112469</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-21T20:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447574#M112470</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/196763"&gt;@mariusmorthorst&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear All&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm using SAS university edition. I'll outline my problem by first outlining my data. &amp;nbsp;I've used the array command to create a variable for each week (in 2008)&amp;nbsp;displaying whether an observation lives in place A or B.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm wondering whether it's possible, using the array command, to&amp;nbsp;create new variables for each sequence respectively and in that variable for the specific sequence report the length of the sequence. &amp;nbsp;In the example above there would at most be 3 new variables (lets call them sequence1, sequence2 and sequence3). For the first observation sequence1 = 2, sequence2 = 3 and sequence3= 2. For the second observation&amp;nbsp;&amp;nbsp;sequence1 = 8, sequence2 = 0 and sequence3= 0.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What rule assigns values to those sequence variables? It isn't obvious to me. Why is sequence 3=2 for the first record, I might think&amp;nbsp;3 was more appropriate for the shown data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And with SAS 9.4 I get an error from spell(I).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are counting sequential recurrence of the same value are you allowing for up to 52 sequence variables? (Assuming that you only have 52 weeks (365 or 366&amp;nbsp;days in a year yields 52 and a fraction weeks so 53 may be needed).&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447574#M112470</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-21T20:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447586#M112477</link>
      <description>&lt;P&gt;Thanks for your quick reply&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;I would like as many sequences as the observation with the most changes has. As i have 52 weeks in the original dataset, this would in theory be the maximum. The data i put up was only a small part used to illustrate the problem at hand.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;And yes your right for the first observation the second sequence should equal 3&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447586#M112477</guid>
      <dc:creator>mariusmorthorst</dc:creator>
      <dc:date>2018-03-21T20:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447604#M112490</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID	(week1 	week2 	week3 	week4	week5	week6	week7	week8) ($);
datalines;
1	A	A	B	B	B	A	A	A
2	B	B	B	B	B	B	B	B
3	B	B	A	A	A	A	A	A
4	A	A	A	A	B	B	B	B
;


data want;
set have;
array t(*) week:;
array s(*) seq1-seq3 ;
i=0;
_count=1;
do _n_=2 to dim(t);
if t(_n_)=t(_n_-1) then _count+1;
else  do;i=i+1;s(i)=_count;_count=1;continue;end;
if _n_=dim(t) then do;i=i+1;s(i)=_count;end;
end;
number_of_sequence=n(of s(*));
drop _: i;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yes you can use arrays. I like your thinking and at the same time I concur with other et al's recommendations too. Have fun and welcome to SAS forum. Cheers!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 21:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447604#M112490</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-21T21:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use arrays to capture "length" of multiple sequences of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447758#M112545</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs;
input ID	(week1 	week2 	week3 	week4	week5	week6	week7	week8) ($);
datalines;
1	A	A	B	B	B	A	A	A
2	B	B	B	B	B	B	B	B
3	B	B	A	A	A	A	A	A
4	A	A	A	A	B	B	B	B
;
proc transpose data=have out=temp;
by id;
var week:;
run;

proc summary data=temp;
by id col1 notsorted;
output out=temp1 ;
run;

proc transpose data=temp1 out=temp2 prefix=seq;
by id;
var _freq_;
run;

data temp3;
 set temp2;
 total=n(of seq:);
 drop _name_;
run;

data want;
 merge have temp3;
 by id;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 13:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-I-use-arrays-to-capture-quot-length-quot-of-multiple/m-p/447758#M112545</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-22T13:03:41Z</dc:date>
    </item>
  </channel>
</rss>

