<?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: How to create rolling arrays in SAS in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232335#M16853</link>
    <description>&lt;P&gt;Attaching a&amp;nbsp;screenshot of the output window (method 1): &amp;nbsp;&amp;nbsp;&lt;img id="robothappy" class="emoticon emoticon-robothappy" src="https://communities.sas.com/i/smilies/16x16_robot-happy.png" alt="Robot Happy" title="Robot Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/684i397B7D1F832219A2/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="boolean_275_days.gif" title="boolean_275_days.gif" /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2015 21:37:29 GMT</pubDate>
    <dc:creator>hbi</dc:creator>
    <dc:date>2015-10-29T21:37:29Z</dc:date>
    <item>
      <title>How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232322#M16847</link>
      <description>I am trying to calculate the dosage of a particular drug for a population to see if any member in this population is over a certain threshold for any 90 consecutive days. So to do this I am thinking that I am going to need to make a arraty that looks at the strengh of this drug over 90 days from an index and if they are all '1' then they get a 'pass', and somehow put this into a do loop to look at all of the potential 90 day windows for a year i=1...i=275 to see if a member at any point during the year has met the criteria. Thoughts?</description>
      <pubDate>Thu, 29 Oct 2015 20:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232322#M16847</guid>
      <dc:creator>cmahrb2</dc:creator>
      <dc:date>2015-10-29T20:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232324#M16848</link>
      <description>Depends on your data structure. What does your data currently look like?</description>
      <pubDate>Thu, 29 Oct 2015 20:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232324#M16848</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-29T20:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232325#M16849</link>
      <description>What would you like to know ?</description>
      <pubDate>Thu, 29 Oct 2015 20:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232325#M16849</guid>
      <dc:creator>cmahrb2</dc:creator>
      <dc:date>2015-10-29T20:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232326#M16850</link>
      <description>What your data currently looks like? Is it formatted in a long or wide format? Do you have a record for every day or are you missing days? If wide, do you have a naming convention? It's much easier if you post sample data and sample output &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 29 Oct 2015 20:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232326#M16850</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-10-29T20:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232331#M16851</link>
      <description>&lt;P&gt;Organize your data to have a threshold for each date for each patient id.&lt;/P&gt;
&lt;P&gt;Sort by id date&lt;/P&gt;
&lt;P&gt;read by id date&lt;/P&gt;
&lt;P&gt;on first.id&amp;nbsp; store save_date, clear flag&lt;/P&gt;
&lt;P&gt;check the threshold on each record&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if thrshold gt target&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subtract date-save_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; if difference gt 90 set flag&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; store save_date&lt;/P&gt;
&lt;P&gt;on last.id check the flag&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 21:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232331#M16851</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2015-10-29T21:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232333#M16852</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give this a try. I created some test data for you. I came up with two possible solutions. Enjoy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;hbi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* not sure if your data actually looks like this; hopefully it's good enough to show these techniques */
/* create 1000 observations with 275 boolean variables */
DATA have;
  LENGTH ID 8 today_minus1-today_minus275 3;
  ARRAY num_array today_minus1-today_minus275;
  DO ID=1 TO 1000;
    DO OVER num_array;
      num_array = floor(ranuni(1234)+0.94);
    END;
    output;
  END;
RUN;


/* method 1: this is the easy way ... */
DATA want1(drop=today_minus1-today_minus275);
  SET have;

  LENGTH cat_275 $300 success_label $100
         find_90_days end_90_days 8;

  cat_275 = CATS(OF today_minus:);
  find_90_days = INDEX(cat_275, REPEAT('1', 90));
  IF find_90_days &amp;gt; 0 THEN DO;
    end_90_days = 275 - INDEX(COMPRESS(REVERSE(cat_275)), REPEAT('1', 90)) + 1;
    success_label = CAT("First occurrence of 90 consecutive days begins at position ", find_90_days, 
                        " and ends at position ", end_90_days);
  END;
RUN;


/* method 2: use arrays ... */
DATA want2(drop=array_loop consecutive_count);
  SET have;

  ARRAY num_array today_minus1-today_minus275;
  LENGTH array_loop consecutive_count best_count 8 success_label $100;

  array_loop        = 0;
  consecutive_count = 0;
  best_count        = 0;

  DO OVER num_array;
    array_loop + 1;
    IF num_array = 1 THEN DO;
      consecutive_count + 1;
      IF consecutive_count &amp;gt;= best_count THEN best_count = consecutive_count;
      IF consecutive_count &amp;gt;= 90 THEN success_label = CAT('First occurrence of 90 consecutive days detected at position: ', array_loop);
    END;
    ELSE consecutive_count = 0;
  END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2015 21:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232333#M16852</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-10-29T21:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create rolling arrays in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232335#M16853</link>
      <description>&lt;P&gt;Attaching a&amp;nbsp;screenshot of the output window (method 1): &amp;nbsp;&amp;nbsp;&lt;img id="robothappy" class="emoticon emoticon-robothappy" src="https://communities.sas.com/i/smilies/16x16_robot-happy.png" alt="Robot Happy" title="Robot Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/684i397B7D1F832219A2/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="boolean_275_days.gif" title="boolean_275_days.gif" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 21:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-rolling-arrays-in-SAS/m-p/232335#M16853</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-10-29T21:37:29Z</dc:date>
    </item>
  </channel>
</rss>

