<?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: Determining the start date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924819#M364019</link>
    <description>Thank you!</description>
    <pubDate>Thu, 18 Apr 2024 13:05:40 GMT</pubDate>
    <dc:creator>twenty7</dc:creator>
    <dc:date>2024-04-18T13:05:40Z</dc:date>
    <item>
      <title>Determining the start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924735#M363986</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data that looks like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dated :date9. accid _f;
format dated date9.;
datalines;
01JAN2023 123 1
01FEB2023 123 1
01MAR2023 123 0
01APR2023 123 1
01MAY2023 123 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there will be 1 record per account per month and the dataset has history going back a couple of years&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to add an additional column which states the date on which the event started (_f). for the above, the want would look like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dated :date9. accid _f start :date9.;
format dated date9. start date9.;
datalines;
01JAN2023 123 1 01JAN2023
01FEB2023 123 1 01JAN2023
01MAR2023 123 0 .
01APR2023 123 1 01APR2023
01MAY2023 123 0 .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the start date would be the first time _f =1 and that should remain the same for each consecutive month where _f=1. The start date would be 'reset' when _f = 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help on how to achieve this would be very much appreciated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 17:43:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924735#M363986</guid>
      <dc:creator>twenty7</dc:creator>
      <dc:date>2024-04-17T17:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Determining the start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924741#M363987</link>
      <description>&lt;P&gt;Thank you for providing a working data step with data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by accid _f notsorted;
   retain start;
   format start date9.;
   If first._f and _f=1 then start=dated;
   else if first._f and _f=0 then call missing(start);
run;&lt;/PRE&gt;
&lt;P&gt;RETAIN tells SAS to keep values of the variable across the data step boundary.&lt;/P&gt;
&lt;P&gt;The BY statement creates automatic variables First.&amp;lt;variable&amp;gt; and Last.&amp;lt;variable&amp;gt; for each variable on the by statement. These values are numeric 1 (true) and 0 (false) indicating where the current observation is the first or last of a group of variables. Normally BY would require the data to be sorted by the option NOTsorted allows the data to have the property that _F does of increase/decrease repeatedly across observations. We include the account so that if the _f from a previous account is 1 and the first _f for this account is 1 they are treated as separate groups (within account).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then simple tests of when to set/reset Start based on the _f.&lt;/P&gt;
&lt;P&gt;The First and Last variables are not written to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2024 18:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924741#M363987</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-17T18:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determining the start date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924819#M364019</link>
      <description>Thank you!</description>
      <pubDate>Thu, 18 Apr 2024 13:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-the-start-date/m-p/924819#M364019</guid>
      <dc:creator>twenty7</dc:creator>
      <dc:date>2024-04-18T13:05:40Z</dc:date>
    </item>
  </channel>
</rss>

