<?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 data step logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36548#M7201</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unless you drop=product on h2, I think you will overlay each successfull merge with REFUND for a product....also, I think AMOUNT will need to be on your by statement (as well as in the SORT by statement) to have a unique key.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Mar 2012 19:28:40 GMT</pubDate>
    <dc:creator>Jay_OAG</dc:creator>
    <dc:date>2012-03-19T19:28:40Z</dc:date>
    <item>
      <title>data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36546#M7199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't seem to figure out this logic with my data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 2 files, Charges and Adjustments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Charges looks like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id date product amount&lt;/P&gt;&lt;P&gt;1 01jan2012 box 20&lt;/P&gt;&lt;P&gt;1 03jan2012 ball 5&lt;/P&gt;&lt;P&gt;1 04jan2012 chair 10&lt;/P&gt;&lt;P&gt;2 02feb2012 camera 100&lt;/P&gt;&lt;P&gt;2 03feb2012 cup 4&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Adjustment looks like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id date product amount&lt;/P&gt;&lt;P&gt;1 03jan2012 refund -5&lt;/P&gt;&lt;P&gt;2 03feb2012 refund -4&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to create a table that removes all adjustments from the charges table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WANT:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id date product amount&lt;/P&gt;&lt;P&gt;1 01jan2012 box 20&lt;/P&gt;&lt;P&gt;1 04jan2012 chair 10&lt;/P&gt;&lt;P&gt;2 02feb2012 camera 100&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the Product variable in the Adjustment table will always be 'refund' and can not match back to Charges. To figure out which rows are to remove Date and Amount variables from Adjustment will have to be used to identify the row to remove from the Charges table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Mar 2012 19:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36546#M7199</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2012-03-19T19:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36547#M7200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h1;&lt;/P&gt;&lt;P&gt;input id $ date : date9. product :$ amount;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 01jan2012 box 20&lt;/P&gt;&lt;P&gt;1 03jan2012 ball 5&lt;/P&gt;&lt;P&gt;1 04jan2012 chair 10&lt;/P&gt;&lt;P&gt;2 02feb2012 camera 100&lt;/P&gt;&lt;P&gt;2 03feb2012 cup 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h2;&lt;/P&gt;&lt;P&gt;input id $ date :date9. product :$ amount;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 03jan2012 refund -5&lt;/P&gt;&lt;P&gt;2 03feb2012 refund -4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge h1 (in=h1) h2(in=h2);&lt;/P&gt;&lt;P&gt;by id date;&lt;/P&gt;&lt;P&gt;if (h1 and not h2);&lt;/P&gt;&lt;P&gt;format date date9.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: if you want to play with hash, here is one of them:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt; set h2(obs=1);&lt;/P&gt;&lt;P&gt; dcl hash h(dataset: 'h2', multidata:'yes');&lt;/P&gt;&lt;P&gt; h.definekey('id','date');&lt;/P&gt;&lt;P&gt; h.definedone();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;format date date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set h1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; _n_=h.find();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if _n_ ne 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Mar 2012 19:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36547#M7200</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-19T19:23:02Z</dc:date>
    </item>
    <item>
      <title>data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36548#M7201</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unless you drop=product on h2, I think you will overlay each successfull merge with REFUND for a product....also, I think AMOUNT will need to be on your by statement (as well as in the SORT by statement) to have a unique key.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Mar 2012 19:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36548#M7201</guid>
      <dc:creator>Jay_OAG</dc:creator>
      <dc:date>2012-03-19T19:28:40Z</dc:date>
    </item>
    <item>
      <title>data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36549#M7202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For your situation , I prefer to Hash Table than Sub-query of SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data h1;
input id $ date : date9. product :$ amount;
format date date9.;
cards;
1 01jan2012 box 20
1 03jan2012 ball 5
1 04jan2012 chair 10
2 02feb2012 camera 100
2 03feb2012 cup 4
;
run;
data h2;
input id $ date :date9. product :$ amount;
format date date9.;
cards;
1 03jan2012 refund -5
2 03feb2012 refund -4
;
run;
data want;
 if _n_ eq 1 then do;
&amp;nbsp; if 0 then set h2(keep=id date);
&amp;nbsp; declare hash ha(hashexp:10,dataset:'h2');
&amp;nbsp;&amp;nbsp; ha.definekey('id','date');
&amp;nbsp;&amp;nbsp; ha.definedone();
 end;
set h1;
 if ha.check() ne 0 then output;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Mar 2012 02:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36549#M7202</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-03-20T02:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: data step logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36550#M7203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One thing learned. Check() is more efficient and thus better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Mar 2012 11:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/data-step-logic/m-p/36550#M7203</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-20T11:07:33Z</dc:date>
    </item>
  </channel>
</rss>

