<?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: Conditionally add an index based on a date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924883#M41507</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set db1;
    by id;
    if first.id and date&amp;lt;='30SEP2022'd then flag=1;
    else if first.id and date&amp;gt;'30SEP2022'd then flag=2
    else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 Apr 2024 17:24:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-04-18T17:24:16Z</dc:date>
    <item>
      <title>Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924852#M41502</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;data DB1;
input ID :$20. Date :date9.;
format Date date9.;
cards;
0001 16FEB2019 
0002 12JAN2017 
0002 22FEB2017
0002 27APR2017
0002 30JAN2019
0003 03MAR2019
..........
;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to ad a column "Index" that has 1 if the date is the first chronologically for each patient and 0 otherwise?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the patient has only one date, the Index should be 1 as in the other cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired Output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;0001&amp;nbsp; &amp;nbsp; &amp;nbsp; 16FEB2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;0002&amp;nbsp; &amp;nbsp; &amp;nbsp;12JAN2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;0002&amp;nbsp; &amp;nbsp; &amp;nbsp;22FEB2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;0002&amp;nbsp; &amp;nbsp; &amp;nbsp;27APR2017&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;0002&amp;nbsp; &amp;nbsp; &amp;nbsp;30JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;0003&amp;nbsp; &amp;nbsp; &amp;nbsp;03MAR2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the dataset has around 30.000 rows. Moreover, this should be done from the start (first date that appears) to 30 days prior to the end (last date).&amp;nbsp; In other words: suppose the end of the study is 31DEC2022 (I know exactly the date), if &lt;U&gt;the first date&lt;/U&gt; for a patient is 11NOV2022 --&amp;gt;, since 11NOV2022 is &amp;lt; 90 days to 31DEC2022 a different index, e.g., 2 should be used to indicate this behaviour.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 16:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924852#M41502</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-04-18T16:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924854#M41503</link>
      <description>&lt;P&gt;Are the dates by ID in increasing chronological order? If not, then sort the data by ID and date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set db1;
    by id;
    if first.id then flag=1;
    else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand this part, and it would help if you explain further and include an example in the sample data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Moreover, this should be done from the start (first date that appears) to 30 days prior to the end (last date).&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 18 Apr 2024 15:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924854#M41503</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-18T15:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924860#M41504</link>
      <description>Thank you very much! I will edit the post</description>
      <pubDate>Thu, 18 Apr 2024 15:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924860#M41504</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-04-18T15:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924868#M41505</link>
      <description>&lt;P&gt;I didn't look carefully, did you include example data where we would need to take into account the last date for the patient?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 16:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924868#M41505</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-18T16:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924876#M41506</link>
      <description>So, the last date is not required. The condition is: if the first date is &amp;gt; 30SEPT2022 (i.e., 90 days before the end of the study) then index = 2&lt;BR /&gt;</description>
      <pubDate>Thu, 18 Apr 2024 17:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924876#M41506</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-04-18T17:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924883#M41507</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set db1;
    by id;
    if first.id and date&amp;lt;='30SEP2022'd then flag=1;
    else if first.id and date&amp;gt;'30SEP2022'd then flag=2
    else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2024 17:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924883#M41507</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-18T17:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally add an index based on a date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924885#M41508</link>
      <description>Thank you very much!</description>
      <pubDate>Thu, 18 Apr 2024 17:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditionally-add-an-index-based-on-a-date/m-p/924885#M41508</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-04-18T17:27:08Z</dc:date>
    </item>
  </channel>
</rss>

