<?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: IML uniqueby with multiple groups in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/384869#M3663</link>
    <description>Thank you for your help. I trust your judgement and will apply accordingly.</description>
    <pubDate>Wed, 02 Aug 2017 07:43:58 GMT</pubDate>
    <dc:creator>MsGeritO</dc:creator>
    <dc:date>2017-08-02T07:43:58Z</dc:date>
    <item>
      <title>IML uniqueby with multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/379332#M3654</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I received a very helpful solution on how to combine an iterative do loop with conditions.&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Search-for-multiple-references-across-two-matrices/m-p/369860#M3545" target="_blank"&gt;https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Search-for-multiple-references-across-two-matrices/m-p/369860#M3545&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the process I had been pointed towards UNIQUEBY. I managed to solve this for a single condition. It, indeed, runs a lot quicker than the previous solution unique-loc. But, again, adding a second condition is so far unsolved or deliveres wrong results. For each ID I would like the sum of euro for dummy1 = 1. Where am I going wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course, I could create new variables (newvar = id + dummy1) and then run the programme over this variable, but that is not preferred.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the part which is fine (one condition):&lt;/P&gt;&lt;P&gt;data somedata;&lt;BR /&gt;input id euro dummy1 dummy2;&lt;BR /&gt;cards;&lt;BR /&gt;1 12 0 1&lt;BR /&gt;1 23 1 1&lt;BR /&gt;1 56 1 1&lt;BR /&gt;1 23 1 0&lt;BR /&gt;2 22 0 1&lt;BR /&gt;2 24 1 1&lt;BR /&gt;2 34 1 1&lt;BR /&gt;2 10 1 0&lt;BR /&gt;3 19 0 1&lt;BR /&gt;3 28 1 1&lt;BR /&gt;3 56 1 1&lt;BR /&gt;3 21 1 0&lt;BR /&gt;4 21 0 1&lt;BR /&gt;4 34 1 1&lt;BR /&gt;4 32 1 1&lt;BR /&gt;4 43 1 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; use work.somedata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; read all;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;call sortn(id);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; uqid = uniqueby(id,1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; totalcost = j(nrow(uqid),1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;uqid = uqid // (nrow(id)+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do i = 1 to nrow(uqid)-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; idx = uqid[i]:(uqid[i+1]-1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalcost[i] = sum(euro[idx]);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print totalcost;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I took guesses to include dummy1 into the sorting and the uqid, but gained no correct calculations.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;call sortn(dummy1, id); *no error message, but does it do the right thing?;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;uqid = uniqueby({dummy1 id},1); *gives back one result for all;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;uqid = uniqueby(dummy1&amp;nbsp;id,1); *gives back error message;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;Gerit&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 11:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/379332#M3654</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2017-07-26T11:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: IML uniqueby with multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/379430#M3655</link>
      <description>&lt;P&gt;I think the uniqueby method might get too complicated when you move to more than one condition.&amp;nbsp;&amp;nbsp; I suggest you create new versions of the euro variable as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  euro_d1 = euro#dummy1;
  euro_d2 = euro#dummy2;
  euro_d12 = euro#dummy1#dummy2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so these will have the amount of money where the dummy (or both dummies) are set, and zero everywhere else.&amp;nbsp;&amp;nbsp; You can then total up the cost using the single condition uniqueby approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 15:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/379430#M3655</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-07-26T15:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: IML uniqueby with multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/384869#M3663</link>
      <description>Thank you for your help. I trust your judgement and will apply accordingly.</description>
      <pubDate>Wed, 02 Aug 2017 07:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/IML-uniqueby-with-multiple-groups/m-p/384869#M3663</guid>
      <dc:creator>MsGeritO</dc:creator>
      <dc:date>2017-08-02T07:43:58Z</dc:date>
    </item>
  </channel>
</rss>

