<?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 . in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883118#M348955</link>
    <description>&lt;P&gt;I ran a quick test to see what combination of BY variables would lead to 6 distinct combinations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have chartype;
  class id--department / missing;
  output out=groups;
run;

proc freq order=freq; 
  tables _type_ / noprint out=counts;
run;

proc print data=counts;
  where count=6;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the result is:&lt;/P&gt;
&lt;PRE&gt;Obs    _TYPE_    COUNT    PERCENT

 25    100010      6      1.76471
 26    100110      6      1.76471
 27    101010      6      1.76471
 28    101110      6      1.76471

&lt;/PRE&gt;
&lt;P&gt;So the minimum set is the first one, 100010, which means the first and fifth variables, ID AND REASON.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So sort by ID and REASON then filter by FIRST.REASON.&amp;nbsp; (Or sort by REASON and ID and filter by first.ID) and you will get 6 observations out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the exact observations you picked manually you will also need to sort by some of the other variables so that the one you want to select is the first one for that combination of ID and REASON.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This list of BY variables works for your example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have ;
  by id reason name ;
run;

proc sort data=expect; 
  by id reason name ;
run;

data want;
  set have;
  by id reason name ;
  if first.reason;
run;

proc compare data=want compare=expect;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Jun 2023 15:33:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-06-30T15:33:02Z</dc:date>
    <item>
      <title>First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883060#M348928</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a datset final in which there are columns like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Id,name,function,status,reason, department and has values&lt;/P&gt;
&lt;P&gt;123,flowers-gift,nw,onboard,blank SLS,human resource&lt;/P&gt;
&lt;P&gt;123,flowers-gifts,nw,onboard,missing country,Human resource&lt;/P&gt;
&lt;P&gt;123,onboard gift,nw,onboard,missing country,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to take unique rows so I performed first. In the dataset&lt;/P&gt;
&lt;P&gt;Data new;&lt;/P&gt;
&lt;P&gt;Set final;&lt;/P&gt;
&lt;P&gt;If first.id and first.name and first.department then output;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output I'm getting is only the first row that is with the reason blank SSL but I also need the second row with missing country.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could anyone please help me on this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 09:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883060#M348928</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-06-30T09:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883063#M348929</link>
      <description>&lt;P&gt;I have a feeling that you are not representing the data in your SAS data set properly. Please provide the data (in this thread, and from now on in all future threads) as &lt;FONT color="#FF6600"&gt;working&lt;/FONT&gt; SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 09:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883063#M348929</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-30T09:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883064#M348930</link>
      <description>You show six variables, but only five values in the data.&lt;BR /&gt;&lt;BR /&gt;Please do ALWAYS post example data in a working DATA step with DATALINES, so we don‘t have to ask.</description>
      <pubDate>Fri, 30 Jun 2023 09:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883064#M348930</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-30T09:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883065#M348931</link>
      <description>Sorry for that.&lt;BR /&gt;I have now edited the it properly</description>
      <pubDate>Fri, 30 Jun 2023 09:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883065#M348931</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-06-30T09:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883066#M348932</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425756"&gt;@Akshaya_1397&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry for that.&lt;BR /&gt;I have now edited the it properly&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not the format we requested.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 09:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883066#M348932</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-30T09:58:04Z</dc:date>
    </item>
    <item>
      <title>first dot in base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883071#M348936</link>
      <description>&lt;P&gt;i have dataset name merged file as shown below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Akshaya_1397_0-1688121932528.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85482iAE14EACEB0C2F624/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Akshaya_1397_0-1688121932528.png" alt="Akshaya_1397_0-1688121932528.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;i wrote a code to obtain unique rows:&lt;BR /&gt;&lt;BR /&gt;DATA fin;&lt;BR /&gt;set Merged_file;&lt;BR /&gt;by&amp;nbsp; ID&amp;nbsp; dep status reason;&lt;BR /&gt;if first.id and first.dep and first.status and first.reason then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;the output which im getiing is only the first row.but the output im expecting is the first two rows as the reason is different&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Akshaya_1397_1-1688122105439.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85483i28F702158A935C16/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Akshaya_1397_1-1688122105439.png" alt="Akshaya_1397_1-1688122105439.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;can anyone please help me on this&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 10:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883071#M348936</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-06-30T10:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: first dot in base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883073#M348937</link>
      <description>&lt;P&gt;Please provide the data in the requested form (we provided a link with examples and instructions). Please don't start new threads on the same topic.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 11:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883073#M348937</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-30T11:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883075#M348935</link>
      <description>So you have the texts „blank SLS“ and „missing country“ in place of missing values?&lt;BR /&gt;&lt;BR /&gt;I will not answer further posts until you post your data as requested.</description>
      <pubDate>Fri, 30 Jun 2023 11:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883075#M348935</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-30T11:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: first dot in base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883076#M348938</link>
      <description>I merged the posts.</description>
      <pubDate>Fri, 30 Jun 2023 11:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883076#M348938</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-30T11:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: first dot in base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883080#M348941</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425756"&gt;@Akshaya_1397&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;i have dataset name merged file as shown below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Akshaya_1397_0-1688121932528.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85482iAE14EACEB0C2F624/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Akshaya_1397_0-1688121932528.png" alt="Akshaya_1397_0-1688121932528.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;i wrote a code to obtain unique rows:&lt;BR /&gt;&lt;BR /&gt;DATA fin;&lt;BR /&gt;set Merged_file;&lt;BR /&gt;by&amp;nbsp; ID&amp;nbsp; dep status reason;&lt;BR /&gt;if first.id and first.dep and first.status and first.reason then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;the output which im getiing is only the first row.but the output im expecting is the first two rows as the reason is different&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Akshaya_1397_1-1688122105439.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85483i28F702158A935C16/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Akshaya_1397_1-1688122105439.png" alt="Akshaya_1397_1-1688122105439.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;can anyone please help me on this&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This test&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.id and first.dep and first.status and first.reason then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;indicates a misunderstanding of how FIRST. flags are created.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That test is the same as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.id then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because the time when all of the FIRST. flags will be true is when you start a new value of the first BY variable, in this case the ID variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to find the distinct observations then you should just test the value of the last BY variable, in this case the REASON variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.reason then output;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 12:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883080#M348941</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-30T12:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: first dot in base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883083#M348942</link>
      <description>&lt;P&gt;Thanks for ur reply tom.&lt;/P&gt;
&lt;P&gt;But we have exact same reasons for other I'd too that's why I used first.id and first.reason.&lt;/P&gt;
&lt;P&gt;Is there any other way to do it?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 12:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883083#M348942</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-06-30T12:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: first dot in base sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883084#M348943</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425756"&gt;@Akshaya_1397&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for ur reply tom.&lt;/P&gt;
&lt;P&gt;But we have exact same reasons for other I'd too that's why I used first.id and first.reason.&lt;/P&gt;
&lt;P&gt;Is there any other way to do it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do WHAT?&lt;/P&gt;
&lt;P&gt;Are you look to get one observation per distinct values of REASON?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then sort by REASON.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=one_per_reason nodupkey ;
  by reason;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2023 12:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883084#M348943</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-30T12:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883086#M348944</link>
      <description>&lt;P&gt;All of the rows in your example dataset are unique already.&amp;nbsp; Please provide example data that has one or more duplicates that you would like to remove.&amp;nbsp; Explain which ones should be removed (or which ones kept) and why.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile cards dsd truncover ;
  input Id $ name :$20. function :$5. status :$20. reason :$20. department :$20.;
cards;
123,flowers-gift,nw,onboard,blank SLS,human resource
123,flowers-gifts,nw,onboard,missing country,Human resource
123,onboard gift,nw,onboard,missing country, 
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    Id         name         function    status     reason               department

 1     123    flowers-gift        nw       onboard    blank SLS          human resource
 2     123    flowers-gifts       nw       onboard    missing country    Human resource
 3     123    onboard gift        nw       onboard    missing country


&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2023 12:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883086#M348944</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-30T12:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883089#M348945</link>
      <description>&lt;P&gt;&lt;BR /&gt;data have ;&lt;BR /&gt;infile cards dsd truncover ;&lt;BR /&gt;input Id $ name :$20. function :$5. status :$20. reason :$20. department :$20.;&lt;BR /&gt;cards;&lt;BR /&gt;123,flowers-gift,nw,onboard,blank SLS,human resource&lt;BR /&gt;123,flowers-gifts,nw,onboard,missing country,Human resource&lt;BR /&gt;123,onboard gift,nw,onboard,missing country,&lt;/P&gt;
&lt;P&gt;124,flowers-gift,nw,onboard,blank SLS,human resource&lt;BR /&gt;124,flowers-gifts,nw,onboard,missing country,Human resource&lt;BR /&gt;124,onboard gift,nw,onboard,missing country,&lt;/P&gt;
&lt;P&gt;125,flowers-gift,nw,onboard,blank SLS,human resource&lt;/P&gt;
&lt;P&gt;126,flowers-gifts,nw,onboard,missing country,Human resource&lt;BR /&gt;126,onboard gift,nw,onboard,missing country,&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;proc sort data= have; by reason; run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data haveuniq;&lt;BR /&gt;set have;&lt;BR /&gt;by reason;&lt;BR /&gt;if first.reason then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;the output which im expecting is shown below:&lt;/P&gt;
&lt;P&gt;123,flowers-gift,nw,onboard,blank SLS,human resource&lt;BR /&gt;123,flowers-gifts,nw,onboard,missing country,Human resource&lt;/P&gt;
&lt;P&gt;124,flowers-gift,nw,onboard,blank SLS,human resource&lt;BR /&gt;124,flowers-gifts,nw,onboard,missing country,Human resource&lt;/P&gt;
&lt;P&gt;125,flowers-gift,nw,onboard,blank SLS,human resource&lt;BR /&gt;126,flowers-gifts,nw,onboard,missing country,Human resource&lt;BR /&gt;&lt;BR /&gt;the output im getting is&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Akshaya_1397_0-1688130439417.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85486i5357803AD377005B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Akshaya_1397_0-1688130439417.png" alt="Akshaya_1397_0-1688130439417.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;this is what is confusing me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 13:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883089#M348945</guid>
      <dc:creator>Akshaya_1397</dc:creator>
      <dc:date>2023-06-30T13:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883095#M348948</link>
      <description>&lt;P&gt;Why does the output confuse you?&amp;nbsp; There are only two distinct values of REASON so you should only get two observations out when selecting based on distinct values of REASON.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1688132370262.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85488i9590162FD33ED648/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1688132370262.png" alt="Tom_0-1688132370262.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the reason that you want to remove the three observations you want removed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only thing I can see that would produce that output would be to just delete the observations with blank values of DEPARTMENT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  infile cards dsd truncover ;
  input Id $ name :$20. function :$5. status :$20. reason :$20. department :$20.;
cards;
123,flowers-gift,nw,onboard,blank SLS,human resource
123,flowers-gifts,nw,onboard,missing country,Human resource
123,onboard gift,nw,onboard,missing country,
124,flowers-gift,nw,onboard,blank SLS,human resource
124,flowers-gifts,nw,onboard,missing country,Human resource
124,onboard gift,nw,onboard,missing country,
125,flowers-gift,nw,onboard,blank SLS,human resource
126,flowers-gifts,nw,onboard,missing country,Human resource
126,onboard gift,nw,onboard,missing country,
;


data expect ;
  infile cards dsd truncover ;
  input Id $ name :$20. function :$5. status :$20. reason :$20. department :$20.;
cards;
123,flowers-gift,nw,onboard,blank SLS,human resource
123,flowers-gifts,nw,onboard,missing country,Human resource
124,flowers-gift,nw,onboard,blank SLS,human resource
124,flowers-gifts,nw,onboard,missing country,Human resource
125,flowers-gift,nw,onboard,blank SLS,human resource
126,flowers-gifts,nw,onboard,missing country,Human resource
;


data no_miss_department;
  set have;
  if not missing(department) then output;
run;

proc compare data=no_miss_department compare=expect;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2023 13:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883095#M348948</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-30T13:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883118#M348955</link>
      <description>&lt;P&gt;I ran a quick test to see what combination of BY variables would lead to 6 distinct combinations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have chartype;
  class id--department / missing;
  output out=groups;
run;

proc freq order=freq; 
  tables _type_ / noprint out=counts;
run;

proc print data=counts;
  where count=6;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the result is:&lt;/P&gt;
&lt;PRE&gt;Obs    _TYPE_    COUNT    PERCENT

 25    100010      6      1.76471
 26    100110      6      1.76471
 27    101010      6      1.76471
 28    101110      6      1.76471

&lt;/PRE&gt;
&lt;P&gt;So the minimum set is the first one, 100010, which means the first and fifth variables, ID AND REASON.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So sort by ID and REASON then filter by FIRST.REASON.&amp;nbsp; (Or sort by REASON and ID and filter by first.ID) and you will get 6 observations out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get the exact observations you picked manually you will also need to sort by some of the other variables so that the one you want to select is the first one for that combination of ID and REASON.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This list of BY variables works for your example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have ;
  by id reason name ;
run;

proc sort data=expect; 
  by id reason name ;
run;

data want;
  set have;
  by id reason name ;
  if first.reason;
run;

proc compare data=want compare=expect;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2023 15:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883118#M348955</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-30T15:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883122#M348956</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/425756"&gt;@Akshaya_1397&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a datset final in which there are columns like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Id,name,function,status,reason, department and has values&lt;/P&gt;
&lt;P&gt;123,flowers-gift,nw,onboard,blank SLS,human resource&lt;/P&gt;
&lt;P&gt;123,flowers-gifts,nw,onboard,missing country,Human resource&lt;/P&gt;
&lt;P&gt;123,onboard gift,nw,onboard,missing country,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;I need to take unique rows so I performed&lt;/STRONG&gt; &lt;/FONT&gt;first. In the dataset&lt;/P&gt;
&lt;P&gt;Data new;&lt;/P&gt;
&lt;P&gt;Set final;&lt;/P&gt;
&lt;P&gt;If first.id and first.name and first.department then output;&lt;/P&gt;
&lt;P&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output I'm getting is only the first row that is with the reason blank SSL but I also need the second row with missing country.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could anyone please help me on this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Assuming your comment in Red is true, SQL is a good option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use SORT (see the examples below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*make test data;

data class;
    set sashelp.class sashelp.class (obs=8);
run;

*select unique records;

proc sql;
    create table distinct_records as 
    select distinct * 
    from class;
quit;

proc sort data=class;
    by _all_;
run;

proc sort data=class noduprecs out=distinct_via_sort;
    by _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2023 15:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883122#M348956</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-06-30T15:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: First. And last .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883180#M348971</link>
      <description>&lt;P&gt;Let's assume you have data sorted by MAJOR_KEY, INTERMEDIATE_KEY, MINOR_KEY.&amp;nbsp; &amp;nbsp;And for some of those triplets, there are duplicates you want to eliminate.&amp;nbsp; &amp;nbsp;If you do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set mydata;
   by major_key intermediate_key minor_key;
   if first.minor_key;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will get one record per unique triplet.&amp;nbsp; It that your goal?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jul 2023 00:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-And-last/m-p/883180#M348971</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-07-01T00:00:21Z</dc:date>
    </item>
  </channel>
</rss>

