<?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: create active flag based on start and end dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840177#M332215</link>
    <description>&lt;P&gt;Let me suggest that you change the names of the flags slightly.&amp;nbsp; For example, instead of active_3_2022 use active_2022_03.&amp;nbsp; That will simplify some of the programming statements and make your variabe names easier to sort if that is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an untested solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array months {24} active_2021_01 - active_2021_12 active_2022_01 - active_2202_12;
   beginning = month(work_start) + 12 * (year(work_start) - 2021);
   ending = month(work_end) + 12 * (year(work_end) - 2021);
   do j = 1 to 24;
      months{j} = (beginning &amp;lt;= j &amp;lt;= ending);
   end;
   drop j beginning ending;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks right.&amp;nbsp; But since yoiu're the one who has the data, you will need to be the one who tests it.&amp;nbsp; If there are any problems with it, please post the log.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2022 02:20:52 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-10-24T02:20:52Z</dc:date>
    <item>
      <title>create active flag based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840173#M332213</link>
      <description>&lt;P&gt;I am trying to get work active flags for each month during past 2 years depending on work start and end dates. My sample is like:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;work_id&lt;/TD&gt;&lt;TD&gt;work_start&lt;/TD&gt;&lt;TD&gt;work_end&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;15JUN2022&lt;/TD&gt;&lt;TD&gt;15JUN2023&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;15MAY2021&lt;/TD&gt;&lt;TD&gt;10MAY2022&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;So, my result will add 24 work active flags from Jan. 2021 to Dec. 2022. Work is active for each month if start before last day of month and end after first of month, result looks like:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;work_id&lt;/TD&gt;&lt;TD&gt;work_start&lt;/TD&gt;&lt;TD&gt;work_end&lt;/TD&gt;&lt;TD&gt;....&lt;/TD&gt;&lt;TD&gt;active_3_2022&lt;/TD&gt;&lt;TD&gt;active_4_2022&lt;/TD&gt;&lt;TD&gt;active_5_2022&lt;/TD&gt;&lt;TD&gt;active_6_2022&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;15MAY2022&lt;/TD&gt;&lt;TD&gt;15JUN2023&lt;/TD&gt;&lt;TD&gt;...&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;TD&gt;1&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;15MAY2021&lt;/TD&gt;&lt;TD&gt;10MAY2022&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 23 Oct 2022 22:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840173#M332213</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2022-10-23T22:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: create active flag based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840177#M332215</link>
      <description>&lt;P&gt;Let me suggest that you change the names of the flags slightly.&amp;nbsp; For example, instead of active_3_2022 use active_2022_03.&amp;nbsp; That will simplify some of the programming statements and make your variabe names easier to sort if that is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an untested solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array months {24} active_2021_01 - active_2021_12 active_2022_01 - active_2202_12;
   beginning = month(work_start) + 12 * (year(work_start) - 2021);
   ending = month(work_end) + 12 * (year(work_end) - 2021);
   do j = 1 to 24;
      months{j} = (beginning &amp;lt;= j &amp;lt;= ending);
   end;
   drop j beginning ending;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks right.&amp;nbsp; But since yoiu're the one who has the data, you will need to be the one who tests it.&amp;nbsp; If there are any problems with it, please post the log.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 02:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840177#M332215</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-24T02:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: create active flag based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840181#M332217</link>
      <description>&lt;P&gt;Thanks for your reply. I got an error when I tried the code. I first create the test data just like my first table:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;work_id&lt;/TD&gt;&lt;TD&gt;work_start&lt;/TD&gt;&lt;TD&gt;work_end&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;15-Jun-22&lt;/TD&gt;&lt;TD&gt;15-Jun-23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;15-May-21&lt;/TD&gt;&lt;TD&gt;10-May-22&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I called it "have", when I ran the code, I got this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasecn_0-1666578837501.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76477iFCF58C74F264C943/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasecn_0-1666578837501.png" alt="sasecn_0-1666578837501.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any idea, what it would be?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 02:34:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840181#M332217</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2022-10-24T02:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: create active flag based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840183#M332219</link>
      <description>&lt;P&gt;My fault, just a typo:&amp;nbsp; active_2202_12 should be active_2022_12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 02:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840183#M332219</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-24T02:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: create active flag based on start and end dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840187#M332222</link>
      <description>&lt;P&gt;Sorry, my bad, I should capture that. The code works. Thanks! Some part of the code, I still don't understand, but&amp;nbsp; I think I can figure it out by some additional readings. Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 03:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-active-flag-based-on-start-and-end-dates/m-p/840187#M332222</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2022-10-24T03:13:17Z</dc:date>
    </item>
  </channel>
</rss>

