<?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: Flag data based on dates (first and last) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Flag-data-based-on-dates-first-and-last/m-p/984360#M43707</link>
    <description>&lt;P&gt;You do not indicate what you want to do if Line is missing or if there is only one observation. However, here is something you can try.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. (Date) (:mmddyy.) Line $8. Treatment :$20.;
  format Date date9.;
cards;
0001 01/09/2024 1st line Chemoth
0001 03/09/2024   .      Radio  
0001 04/09/2024   .      Radio 
0001 09/13/2024 1st line Chemoth
0002 11/09/2016 1st line Chemoth 
0003 06/30/2025 2nd line Chemoth 
0003 07/31/2025 2nd line Chemoth 
0004 03/12/2024    .     Radio 
;
run;

proc sort data=db;
by id line treatment;
run;

data db1;
set db;
by id line treatment;
if last.treatment and line='1st line' then flag=1;
else if first.treatment and line='2nd line' then flag=1;
else flag=0;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have additional questions, please show what you are expecting based on the data you sent.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Mar 2026 14:09:18 GMT</pubDate>
    <dc:creator>Kathryn_SAS</dc:creator>
    <dc:date>2026-03-04T14:09:18Z</dc:date>
    <item>
      <title>Flag data based on dates (first and last)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-data-based-on-dates-first-and-last/m-p/984357#M43706</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following dataset:&lt;/P&gt;
&lt;PRE&gt;data DB;
  input ID :$20. (Date) (:mmddyy.) Line :$20. Treatment :$20.;
  format Date date9.;
cards;
0001 01/09/2024   1st line   Chemoth
0001 03/09/2024     .        Radio  
0001 04/09/2024     .        Radio 
0001 09/13/2024   1st line   Chemoth
0002 11/09/2016   1st line   Chemoth 
0003 06/30/2025   2nd line   Chemoth 
0003 07/31/2025   2nd line   Chemoth 
0004 03/12/2024      .       Radio 
;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Is there a way to&amp;nbsp; flag the following: "if more than one 1st line of Chemotherapy was done, then take the Date of the last"?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, is there a way to flag the following: "if more than one 2nd line of Chemotherapy was done, then take the Date of the first"?&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 put both rules in the same piece of code?&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;</description>
      <pubDate>Wed, 04 Mar 2026 13:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-data-based-on-dates-first-and-last/m-p/984357#M43706</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2026-03-04T13:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: Flag data based on dates (first and last)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-data-based-on-dates-first-and-last/m-p/984360#M43707</link>
      <description>&lt;P&gt;You do not indicate what you want to do if Line is missing or if there is only one observation. However, here is something you can try.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. (Date) (:mmddyy.) Line $8. Treatment :$20.;
  format Date date9.;
cards;
0001 01/09/2024 1st line Chemoth
0001 03/09/2024   .      Radio  
0001 04/09/2024   .      Radio 
0001 09/13/2024 1st line Chemoth
0002 11/09/2016 1st line Chemoth 
0003 06/30/2025 2nd line Chemoth 
0003 07/31/2025 2nd line Chemoth 
0004 03/12/2024    .     Radio 
;
run;

proc sort data=db;
by id line treatment;
run;

data db1;
set db;
by id line treatment;
if last.treatment and line='1st line' then flag=1;
else if first.treatment and line='2nd line' then flag=1;
else flag=0;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have additional questions, please show what you are expecting based on the data you sent.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2026 14:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-data-based-on-dates-first-and-last/m-p/984360#M43707</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2026-03-04T14:09:18Z</dc:date>
    </item>
  </channel>
</rss>

