<?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: Trouble Understanding SAS Question and Process to reach Solution in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610313#M18073</link>
    <description>&lt;P&gt;This should be closer to the right answer:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CLAIMS1 Claims2;
       set CLAIMS;
       by ID_NUM CLAIM_NUM;
       if first.CLAIM_NUM and last.CLAIM_NUM then Output Claims1;
       else Output Claims2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to use&amp;nbsp;&lt;CODE class=" language-sas"&gt;CLAIM_NUM for your FIRST. and LAST. processing and by checking both you are outputting unique claims by ID_NUM. All other rows must then be not unique by claim.&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Dec 2019 18:59:21 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2019-12-08T18:59:21Z</dc:date>
    <item>
      <title>Trouble Understanding SAS Question and Process to reach Solution</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610309#M18070</link>
      <description>&lt;P&gt;Here is the Problem:&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Assume you have a SAS data set (called CLAIMS) that contains pharmacy claims. Each claim should be uniquely identified by the patient's identification number (ID_NUM) and a transaction number (Claim_Num). (E.g., patient 001 should not have more than one record with Claim_Num = 123).&amp;nbsp; You want to be able to inspect any claims for which there are possible duplicate records.&amp;nbsp; Write the SAS code to separate the observations into 2 new SAS data sets.&amp;nbsp; One data set will hold all the observations where the combination of ID_NUM and Claim_Num are unduplicated (that is, there is only one claim with a particular ID_NUM and Claim_Num combination), and a second data set that will hold all the records (including the first) where there are duplicates of Claim_Num for a given ID_NUM.&amp;nbsp; (HINT: you will need to use first. and last. to do this).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here is what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=CLAIMS;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;by ID_NUM CLAIM_NUM;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data CLAIMS1 Claims2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set CLAIMS;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;by ID_NUM CLAIM_NUM;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if first.ID_NUM = 1;&lt;BR /&gt;Output Claims1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if first.ID_NUM = 1 and last.ID_NUM = 1;&lt;BR /&gt;Output Claims2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this is wrong because I tried&amp;nbsp; a sample data set and there was no output for claims2. I think the error is first.id_num being = to 1 in both cases but I just can't think of how to properly separate the two sets of data. If anyone can help me figure out this problem, it would be greatly appreciated. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 18:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610309#M18070</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2019-12-08T18:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Understanding SAS Question and Process to reach Solution</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610312#M18072</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295349"&gt;@K_Wils15&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the problem comes from the by variable -&amp;gt; you need to take into account first/last.CLAIM_NUM rather than&amp;nbsp; first/last.ID_NUM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CLAIMS;
	input ID_NUM $ CLAIM_NUM;
	cards;
001 1
001 123
001 123
002 234
002 234
002 234
002 999
;
run;

proc sort data=CLAIMS;
       by ID_NUM CLAIM_NUM;
run;

data CLAIMS_NO_DUP CLAIMS2_WITH_DUP;
	set CLAIMS;
	by ID_NUM CLAIM_NUM;
	if first.CLAIM_NUM = 1 and last.CLAIM_NUM = 1 then Output CLAIMS_NO_DUP;
    else output CLAIMS2_WITH_DUP;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Dec 2019 18:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610312#M18072</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-08T18:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Understanding SAS Question and Process to reach Solution</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610313#M18073</link>
      <description>&lt;P&gt;This should be closer to the right answer:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data CLAIMS1 Claims2;
       set CLAIMS;
       by ID_NUM CLAIM_NUM;
       if first.CLAIM_NUM and last.CLAIM_NUM then Output Claims1;
       else Output Claims2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to use&amp;nbsp;&lt;CODE class=" language-sas"&gt;CLAIM_NUM for your FIRST. and LAST. processing and by checking both you are outputting unique claims by ID_NUM. All other rows must then be not unique by claim.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Dec 2019 18:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trouble-Understanding-SAS-Question-and-Process-to-reach-Solution/m-p/610313#M18073</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-12-08T18:59:21Z</dc:date>
    </item>
  </channel>
</rss>

