<?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: First. and last. statement for duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752157#M236890</link>
    <description>&lt;P&gt;How is the posted code not doing what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you are first removing any observations where ID is missing with the subsetting IF statement.&lt;/P&gt;
&lt;P&gt;You are then removing any extra observations per ID so that you keep only the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a subsetting IF statement before testing the FIRST.ID flag could have, in theory, caused a problem as it could have removed the observation where FIRST.ID is true.&amp;nbsp; But since you are removing all of the observations where ID is missing it doesn't really cause any trouble.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step is equivalent to these other forms:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ler3;
  set ler2;
  by id;
  where id ne . ;
  if first.id then output;
run;

data ler3;
  set ler2;
  by id;
  if first.id and id ne . then output;
run;

data ler3;
  set ler2;
  by id;
  if first.id and id ne . ;
run;


data ler3;
  set ler2;
  by id;
  if id=. or not first.id then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Jul 2021 20:18:50 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-07-05T20:18:50Z</dc:date>
    <item>
      <title>First. and last. statement for duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752144#M236880</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;I am working on a dataset in which there are duplicate observations to a death record. I used First. statement to find these duplicates.&lt;/P&gt;&lt;P&gt;My question now is: If I wanted to select only the first record for each participant, how do I go about implementing this?&lt;/P&gt;&lt;P&gt;I know I can use the First. And/or Last. statement in SAS but i can't seem to figure this out. My codes are attached below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= ler2;

 by id;

 run;

 data ler3;

 set ler2;

 by id;

 if id ne .;

 if first.id then output;

 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv3103621543MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv3103621543MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 18:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752144#M236880</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2021-07-05T18:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: First. and last. statement for duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752146#M236882</link>
      <description>&lt;P&gt;Try removing the missing values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc sort data= ler2;

 by id;

run;

data ler3;

 set ler2 (where=( id ne .));

 by id;

 if first.id then 
    output;

run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 18:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752146#M236882</guid>
      <dc:creator>felipe_campos</dc:creator>
      <dc:date>2021-07-05T18:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: First. and last. statement for duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752157#M236890</link>
      <description>&lt;P&gt;How is the posted code not doing what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you are first removing any observations where ID is missing with the subsetting IF statement.&lt;/P&gt;
&lt;P&gt;You are then removing any extra observations per ID so that you keep only the first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a subsetting IF statement before testing the FIRST.ID flag could have, in theory, caused a problem as it could have removed the observation where FIRST.ID is true.&amp;nbsp; But since you are removing all of the observations where ID is missing it doesn't really cause any trouble.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step is equivalent to these other forms:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ler3;
  set ler2;
  by id;
  where id ne . ;
  if first.id then output;
run;

data ler3;
  set ler2;
  by id;
  if first.id and id ne . then output;
run;

data ler3;
  set ler2;
  by id;
  if first.id and id ne . ;
run;


data ler3;
  set ler2;
  by id;
  if id=. or not first.id then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 20:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-last-statement-for-duplicates/m-p/752157#M236890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-05T20:18:50Z</dc:date>
    </item>
  </channel>
</rss>

