<?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: want to knock off the records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654093#M196497</link>
    <description>&lt;P&gt;i have a dataset like below intially&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset1&lt;/P&gt;
&lt;P&gt;Loanno&amp;nbsp; &amp;nbsp; &amp;nbsp;dramt&amp;nbsp; &amp;nbsp; &amp;nbsp;cramt&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;dataset2&lt;/P&gt;
&lt;P&gt;refno&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; creditamount&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;The merging should be done based on Loanno and&amp;nbsp; &amp;nbsp;if dramt = creditamount then flag should come as "Matched" and i need the original data as it is in the intial stage . So i have used the code like below.&lt;/P&gt;
&lt;P&gt;proc sort data =data1;by loanno dramt ;run;&lt;/P&gt;
&lt;P&gt;proc sort data=data2&amp;nbsp; ;by loanno creditamount;run;&lt;/P&gt;
&lt;P&gt;data first;&lt;/P&gt;
&lt;P&gt;set data1;&lt;/P&gt;
&lt;P&gt;by loanno ;&lt;/P&gt;
&lt;P&gt;if first.loanno =1 then d=1;else d+1;run;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;data second;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;set data2;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;by refno;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;if first.refno=1 then d=1; else d+1;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;merge data1 (in=a)&amp;nbsp; &amp;nbsp; &amp;nbsp;data2(in=b);&lt;/P&gt;
&lt;P&gt;by loanno amount d;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;I have named loanno1 as common in both the datasets and i have merged .As i need the structure of original data after merging also .So to avoid overlapping of records i have generated a distinct value using D and i have merged&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jun 2020 03:07:25 GMT</pubDate>
    <dc:creator>rohithverma</dc:creator>
    <dc:date>2020-06-08T03:07:25Z</dc:date>
    <item>
      <title>want to knock off the records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654086#M196490</link>
      <description>&lt;P&gt;I have a data like below :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Loanno&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dramt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;refno&amp;nbsp; &amp;nbsp; &amp;nbsp;creditamt&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1234&amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1234&amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp;100&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need output like below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset1:-&lt;/P&gt;
&lt;P&gt;Loanno&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dramt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;refno&amp;nbsp; &amp;nbsp; &amp;nbsp;creditamt&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset2:-&lt;/P&gt;
&lt;P&gt;Loanno&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dramt&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;refno&amp;nbsp; &amp;nbsp; &amp;nbsp;creditamt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; 50&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me . thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 02:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654086#M196490</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-06-08T02:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: want to knock off the records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654088#M196492</link>
      <description>What are the rules there? Why does the missing get split between the data sets?&lt;BR /&gt;&lt;BR /&gt;If it's positional - ie last record in one data set and others in second dataset that's trivial with first/last. &lt;BR /&gt;&lt;BR /&gt;data part1 part2;&lt;BR /&gt;set have;&lt;BR /&gt;by loanno dramt;&lt;BR /&gt;if last.loanno then output part2;&lt;BR /&gt;else output part1;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 08 Jun 2020 02:41:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654088#M196492</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-08T02:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: want to knock off the records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654089#M196493</link>
      <description>&lt;P&gt;Sorry it won't&amp;nbsp; be positional .Dynamically the records order will change .&lt;/P&gt;
&lt;P&gt;Due to one to one merging i have got those dots mean missing values&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 02:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654089#M196493</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-06-08T02:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: want to knock off the records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654090#M196494</link>
      <description>&lt;P&gt;So what is the logic. Why do some dots go to one data set and others to the other dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should fix your join, not fix it after the fact. This means that you have records in one data set that don't match in the other OR that you have missing in both and it's joining on the missing. Check your data before the merge and after to ensure you're getting the correct results.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 02:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654090#M196494</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-08T02:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: want to knock off the records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654093#M196497</link>
      <description>&lt;P&gt;i have a dataset like below intially&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dataset1&lt;/P&gt;
&lt;P&gt;Loanno&amp;nbsp; &amp;nbsp; &amp;nbsp;dramt&amp;nbsp; &amp;nbsp; &amp;nbsp;cramt&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;dataset2&lt;/P&gt;
&lt;P&gt;refno&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; creditamount&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;
&lt;P&gt;1234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;The merging should be done based on Loanno and&amp;nbsp; &amp;nbsp;if dramt = creditamount then flag should come as "Matched" and i need the original data as it is in the intial stage . So i have used the code like below.&lt;/P&gt;
&lt;P&gt;proc sort data =data1;by loanno dramt ;run;&lt;/P&gt;
&lt;P&gt;proc sort data=data2&amp;nbsp; ;by loanno creditamount;run;&lt;/P&gt;
&lt;P&gt;data first;&lt;/P&gt;
&lt;P&gt;set data1;&lt;/P&gt;
&lt;P&gt;by loanno ;&lt;/P&gt;
&lt;P&gt;if first.loanno =1 then d=1;else d+1;run;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;data second;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;set data2;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;by refno;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;if first.refno=1 then d=1; else d+1;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;merge data1 (in=a)&amp;nbsp; &amp;nbsp; &amp;nbsp;data2(in=b);&lt;/P&gt;
&lt;P&gt;by loanno amount d;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;I have named loanno1 as common in both the datasets and i have merged .As i need the structure of original data after merging also .So to avoid overlapping of records i have generated a distinct value using D and i have merged&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 03:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654093#M196497</guid>
      <dc:creator>rohithverma</dc:creator>
      <dc:date>2020-06-08T03:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: want to knock off the records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654100#M196502</link>
      <description>&lt;P&gt;What you show us in your latest post and what you've posted initially doesn't align - plus the code you've posted now throws errors if executed.&lt;/P&gt;
&lt;P&gt;Going back to your initial question below code returns what you've asked for. If that's also going to work with your real data will depend on how representative the sample is you've provided (like: I'm missing a datetime column in your sample data).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Loanno dramt refno creditamt;
  datalines;
 . . 1234 50
 . . 1234 50
 . . 1234 100
1234 100 . . 
;

data want1 want2;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(where=(not missing(loanno)))', multidata:'y');
      h1.defineKey('loanno', 'dramt');
      h1.defineData('Loanno', 'dramt');
      h1.defineDone();
    end;

  set have;
  if h1.check(key:refno,key:creditamt)=0 then
    do;
      output want1;
      h1.removedup(key:refno,key:creditamt);
    end;
  else if not missing(loanno) then output want1;
  else output want2;
run;

proc print data=want1;
run;
proc print data=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 04:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-knock-off-the-records/m-p/654100#M196502</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-08T04:05:06Z</dc:date>
    </item>
  </channel>
</rss>

