<?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 Please, please help! Trying to use an array statement to identify duration of an event, can't find what's wrong. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138588#M37190</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, looking for some answers.&amp;nbsp; Already looked at the help page for array statements, but couldn't see anything related to my issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm examining the presence of an event over each month for the last two years, and have created a binary variable for each month ("1" if event was present, "0" if not).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, whenever there is a "1" present, I need to know how many months it lasts.&amp;nbsp; For example, if month1, month2, and month3 all had 1's, I would need SAS to provide the number 3.&amp;nbsp; The tricky part is that there can be multiple groupings for each case.&amp;nbsp; For example, months 1 2 and 3 can all have "1", but months 19, 20, and 21 can also have "1"s.&amp;nbsp; So, I would need SAS to tell me there were two separate instances for one case where the event lasted 3 months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried using the following code someone else gave me to no avail:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;data new; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;array months (24) month1-month24;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&amp;nbsp; do i=1 to 24 until (months(i) ne 0) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if months(i)=0 then duration=i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&amp;nbsp;&amp;nbsp; end; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000;"&gt;What this does is create a variable "i", which identifies the first month for a case that a "1" appears, and the variable "duration," which identifies the month where the last "0" appeared.&amp;nbsp; Any ideas on how to make this array do what I described ?&amp;nbsp; Thanks so much.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Jan 2014 09:09:50 GMT</pubDate>
    <dc:creator>xlwolfshirt</dc:creator>
    <dc:date>2014-01-12T09:09:50Z</dc:date>
    <item>
      <title>Please, please help! Trying to use an array statement to identify duration of an event, can't find what's wrong.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138588#M37190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, looking for some answers.&amp;nbsp; Already looked at the help page for array statements, but couldn't see anything related to my issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm examining the presence of an event over each month for the last two years, and have created a binary variable for each month ("1" if event was present, "0" if not).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, whenever there is a "1" present, I need to know how many months it lasts.&amp;nbsp; For example, if month1, month2, and month3 all had 1's, I would need SAS to provide the number 3.&amp;nbsp; The tricky part is that there can be multiple groupings for each case.&amp;nbsp; For example, months 1 2 and 3 can all have "1", but months 19, 20, and 21 can also have "1"s.&amp;nbsp; So, I would need SAS to tell me there were two separate instances for one case where the event lasted 3 months.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried using the following code someone else gave me to no avail:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;data new; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;array months (24) month1-month24;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&amp;nbsp; do i=1 to 24 until (months(i) ne 0) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if months(i)=0 then duration=i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&amp;nbsp;&amp;nbsp; end; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d; font-size: 11pt; font-family: Calibri,sans-serif;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000;"&gt;What this does is create a variable "i", which identifies the first month for a case that a "1" appears, and the variable "duration," which identifies the month where the last "0" appeared.&amp;nbsp; Any ideas on how to make this array do what I described ?&amp;nbsp; Thanks so much.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jan 2014 09:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138588#M37190</guid>
      <dc:creator>xlwolfshirt</dc:creator>
      <dc:date>2014-01-12T09:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Please, please help! Trying to use an array statement to identify duration of an event, can't find what's wrong.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138589#M37191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is probably a more direct way, but the following (I think) accomplishes what you want to do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id month1-month24;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 1 . 1 1 . 1 1 . . . 1 1 . . . 1 1 . 1 1 . 1 1 .&lt;/P&gt;&lt;P&gt;2 . . 1 1 1 . . . 1 1 . 1 1 1 1 . . . 1 1 . 1 1 1&lt;/P&gt;&lt;P&gt;3 . 1 1 1 1 1 1 . 1 1 1 1 1 1 1 . 1 1 1 1 1 1 . .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=i counter durations:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array months(*) month1-month24;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array durations(12);&lt;/P&gt;&lt;P&gt;&amp;nbsp; call missing(of durations(*));&lt;/P&gt;&lt;P&gt;&amp;nbsp; if months(1) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; durations(counter)+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else counter=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=2 to dim(months);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if months(i) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(months(i-1)) then counter+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; durations(counter)+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call sortn(of durations(*));&lt;/P&gt;&lt;P&gt;&amp;nbsp; i=11;&lt;/P&gt;&lt;P&gt;&amp;nbsp; max=durations(12);&lt;/P&gt;&lt;P&gt;&amp;nbsp; call missing(instances);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not missing(max) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; instances=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do while (durations(i) eq max);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; instances+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jan 2014 15:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138589#M37191</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-01-12T15:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Please, please help! Trying to use an array statement to identify duration of an event, can't find what's wrong.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138590#M37192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Besides Art's answer, I think this thread may&amp;nbsp; be relevant to your questions:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" class="active_link" href="https://communities.sas.com/thread/52032"&gt;https://communities.sas.com/thread/52032&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you find my part of answer interesting and need assistance to develop a solution for your very problem, I am here happy to help; I believe same goes with PG, who is much nicer than me &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jan 2014 20:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138590#M37192</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-01-12T20:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: Please, please help! Trying to use an array statement to identify duration of an event, can't find what's wrong.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138591#M37193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know if this is really all that more direct than Arthur's solution but it has fewer lines of code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data havea;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array mn(24) month1-month24;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array nm(24) _TEMPORARY_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array sb(24) _TEMPORARY_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array lg(24) _TEMPORARY_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 24;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nm(i) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mn(i) = 1 then sb(i) = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else sb(i) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mn(i) = 1 and i = 1 then nm(i) = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if sb(i) = 1 then nm(i) = (sb(i)) + (nm(i-1));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else nm(i) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; long = max(of nm&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do j = 1 to 24;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if nm(j) = long then lg(j) = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else lg(j) = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; times = sum(of lg&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Jan 2014 20:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-please-help-Trying-to-use-an-array-statement-to-identify/m-p/138591#M37193</guid>
      <dc:creator>overmar</dc:creator>
      <dc:date>2014-01-12T20:52:07Z</dc:date>
    </item>
  </channel>
</rss>

