<?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 presence/absence based in a variable values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951169#M42748</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID $ (Start End) (:date.) Place ;
  format start end date9.;
cards;
0001 13JAN2015 20JAN2015 0
0001 21JAN2015 31DEC2015 1
0001 01JAN2018 31DEC2018 0
0001 01JAN2019 31DEC2019 1
0002 01JAN2015 31DEC2015 1
0002 01JAN2019 31OCT2019 0
0002 01NOV2019 31DEC2020 0
;

data want;
 set have;
 by id;
 retain found_1 found_0 ;
 if first.id then call missing(found_1,found_0);
 first_1=0;first_0=0;
 if Place=1 and not found_1 then do;first_1=1;found_1=1;end;
 if Place=0 and not found_0 then do;first_0=1;found_0=1;end;
 drop found_:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Nov 2024 01:22:12 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-11-19T01:22:12Z</dc:date>
    <item>
      <title>Flag presence/absence based in a variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951122#M42745</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID $ (Start End) (:date.) Place $;
  format start end date9.;
cards;
0001 13JAN2015 20JAN2015 0
0001 21JAN2015 31DEC2015 1
0001 01JAN2018 31DEC2018 0
0001 01JAN2019 31DEC2019 1
0002 01JAN2015 31DEC2015 1
0002 01JAN2019 31OCT2019 0
0002 01NOV2019 31DEC2020 0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to add two variables (with 1 = yes, 0= no): one indicating the first date the patient has Place = 1 ever in his life and another indicating the first date the patient has Place = 0 ever in his life?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID $ (Start End) (:date.) Place First_1 First_0 $;
  format start end date9.;
cards;
0001 13JAN2015 20JAN2015 0 0  1
0001 21JAN2015 31DEC2015 1 1  0
0001 01JAN2018 31DEC2018 0 0  0
0001 01JAN2019 31DEC2019 1 0  0
0002 01JAN2015 31DEC2015 1 1  0
0002 01JAN2019 31OCT2019 0 0  1
0002 01NOV2019 31DEC2020 0 0  0
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 17:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951122#M42745</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-11-18T17:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Flag presence/absence based in a variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951133#M42747</link>
      <description>&lt;PRE&gt;data have;
  input ID $ (Start End) (:date.) Place $;
  format start end date9.;
cards;
0001 13JAN2015 20JAN2015 0
0001 21JAN2015 31DEC2015 1
0001 01JAN2018 31DEC2018 0
0001 01JAN2019 31DEC2019 1
0002 01JAN2015 31DEC2015 1
0002 01JAN2019 31OCT2019 0
0002 01NOV2019 31DEC2020 0
;

proc sort data= have;
   by id place start;
run;

data want;
   set have;
   by id place start;
   first_1 = (first.place and place='1');
   first_0 = (first.place and place='0');
run;

proc sort data=want;
   by id start;
run;
&lt;/PRE&gt;
&lt;P&gt;First and/or Last are available with BY group processing in a data step. Each variable on the BY has its own indicator accessed using the First.Variable or Last.Variable. The values are 1 for True or 0 for False.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And why is your "place" variable character if it only has 1 and 0 for values? Kind of odd.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 18:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951133#M42747</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-11-18T18:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Flag presence/absence based in a variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951169#M42748</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID $ (Start End) (:date.) Place ;
  format start end date9.;
cards;
0001 13JAN2015 20JAN2015 0
0001 21JAN2015 31DEC2015 1
0001 01JAN2018 31DEC2018 0
0001 01JAN2019 31DEC2019 1
0002 01JAN2015 31DEC2015 1
0002 01JAN2019 31OCT2019 0
0002 01NOV2019 31DEC2020 0
;

data want;
 set have;
 by id;
 retain found_1 found_0 ;
 if first.id then call missing(found_1,found_0);
 first_1=0;first_0=0;
 if Place=1 and not found_1 then do;first_1=1;found_1=1;end;
 if Place=0 and not found_0 then do;first_0=1;found_0=1;end;
 drop found_:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Nov 2024 01:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-presence-absence-based-in-a-variable-values/m-p/951169#M42748</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-19T01:22:12Z</dc:date>
    </item>
  </channel>
</rss>

