<?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: Re-code each element of a vector efficiently in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283726#M2899</link>
    <description>&lt;P&gt;Thanks Rick, this solution looks good, it was exactly what I was looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I unfortunately only have SAS 9.2 so I am unable to invoke the BIN function&amp;nbsp;&lt;img id="mansad" class="emoticon emoticon-mansad" src="https://communities.sas.com/i/smilies/16x16_man-sad.png" alt="Man Sad" title="Man Sad" /&gt; However, I'll retain this for future use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much appreciated,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jul 2016 09:59:43 GMT</pubDate>
    <dc:creator>Andrew_</dc:creator>
    <dc:date>2016-07-12T09:59:43Z</dc:date>
    <item>
      <title>Re-code each element of a vector efficiently</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283487#M2892</link>
      <description>&lt;P&gt;I'm perhaps over-complicating this problem, and for various reasons I'm keen to keep this in IML as it is part of an iterative process which&amp;nbsp;requires matrix calculations later on. &amp;nbsp;I wondered if there was some way I could use the LOC function but thinking probably not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;High level description of problem&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I have a list of percentages. &amp;nbsp;The percentages&amp;nbsp;determine the rate you receive. &amp;nbsp;I want to re-code the original percentages in one vector into the target&amp;nbsp;rates in another vector. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Detail&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wish to re-code each element of &lt;STRONG&gt;Vector A &lt;/STRONG&gt;into a value in &lt;STRONG&gt;Vector C. &lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Vector B&lt;/STRONG&gt;&amp;nbsp;lets us determine the column of Vector C we want to return. So, any element&amp;nbsp;with value less than or equal to 0.5 falls into category 1 (i.e. that is returns 0.02 from Vector C); between 0.51 and 0.55 (inclusive) would be category 2, and so on. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So, in this example,&amp;nbsp;element 1 of Vector A is 0.78 - it falls into category 7 (determined by vector B). &amp;nbsp;Therefore,&amp;nbsp;element 1 of the resulting vector will be&amp;nbsp;0.08 (which matches column &lt;STRONG&gt;7&lt;/STRONG&gt; of vector C).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Vector&amp;nbsp;A&lt;/STRONG&gt;&amp;nbsp;contains the percentages which I want to re-code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;M1&lt;/TD&gt;&lt;TD&gt;M2&lt;/TD&gt;&lt;TD&gt;M3&lt;/TD&gt;&lt;TD&gt;M4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.78&lt;/TD&gt;&lt;TD&gt;0.75&lt;/TD&gt;&lt;TD&gt;0.72&lt;/TD&gt;&lt;TD&gt;0.69&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class="container"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Vector B&lt;/STRONG&gt; contains&amp;nbsp;contains&amp;nbsp;the categories (these allow me to determine which column of vector C i need).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;LookupVector&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;0.55&lt;/TD&gt;&lt;TD&gt;0.6&lt;/TD&gt;&lt;TD&gt;0.65&lt;/TD&gt;&lt;TD&gt;0.7&lt;/TD&gt;&lt;TD&gt;0.75&lt;/TD&gt;&lt;TD&gt;0.8&lt;/TD&gt;&lt;TD&gt;0.85&lt;/TD&gt;&lt;TD&gt;0.9&lt;/TD&gt;&lt;TD&gt;0.95&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Vector&amp;nbsp;C&lt;/STRONG&gt; contains the target rates&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Match50&lt;/TD&gt;&lt;TD&gt;Match55&lt;/TD&gt;&lt;TD&gt;Match60&lt;/TD&gt;&lt;TD&gt;Match65&lt;/TD&gt;&lt;TD&gt;Match70&lt;/TD&gt;&lt;TD&gt;Match75&lt;/TD&gt;&lt;TD&gt;Match80&lt;/TD&gt;&lt;TD&gt;Match85&lt;/TD&gt;&lt;TD&gt;Match90&lt;/TD&gt;&lt;TD&gt;Match95&lt;/TD&gt;&lt;TD&gt;Match100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.02&lt;/TD&gt;&lt;TD&gt;0.03&lt;/TD&gt;&lt;TD&gt;0.04&lt;/TD&gt;&lt;TD&gt;0.05&lt;/TD&gt;&lt;TD&gt;0.06&lt;/TD&gt;&lt;TD&gt;0.07&lt;/TD&gt;&lt;TD&gt;0.08&lt;/TD&gt;&lt;TD&gt;0.09&lt;/TD&gt;&lt;TD&gt;0.1&lt;/TD&gt;&lt;TD&gt;0.11&lt;/TD&gt;&lt;TD&gt;0.12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output would look like this :&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&lt;TABLE cellspacing="1" cellpadding="7"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;0.08&lt;/TD&gt;&lt;TD&gt;0.07&lt;/TD&gt;&lt;TD&gt;0.07&lt;/TD&gt;&lt;TD&gt;0.06&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;I have solved this using two&amp;nbsp;DO loops (see attached), but I really believe this won't be the most efficient way to do it. &amp;nbsp;This will be repeated many times so removing any loops will be important. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 14:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283487#M2892</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2016-07-11T14:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Re-code each element of a vector efficiently</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283494#M2893</link>
      <description>&lt;P&gt;Sure, you need to use the BIN function, which enables you to specify cut points. The values of A are binned into integer indices that correspond to the cut points in B. &amp;nbsp;You can then use those indices to extract the target rates in the C vector.&lt;/P&gt;
&lt;P&gt;For reference, you can read about the BIN function in the article &lt;A href="http://blogs.sas.com/content/iml/2013/07/15/cut-pts-and-uneven-bins.html" target="_self"&gt;"Bin observations by using custom cut points"&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
A = {0.78	0.75	0.72	0.69};  /* values */
B = 0 || do(0.5, 1, 0.05);      /* cutpoints */
binIdx = bin(A, B);
C = do(0.02, 0.12, 0.01);
RatesForA = C[,binIdx];
print RatesForA;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jul 2016 14:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283494#M2893</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-07-11T14:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Re-code each element of a vector efficiently</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283726#M2899</link>
      <description>&lt;P&gt;Thanks Rick, this solution looks good, it was exactly what I was looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I unfortunately only have SAS 9.2 so I am unable to invoke the BIN function&amp;nbsp;&lt;img id="mansad" class="emoticon emoticon-mansad" src="https://communities.sas.com/i/smilies/16x16_man-sad.png" alt="Man Sad" title="Man Sad" /&gt; However, I'll retain this for future use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much appreciated,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 09:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283726#M2899</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2016-07-12T09:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Re-code each element of a vector efficiently</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283727#M2900</link>
      <description>&lt;P&gt;Please engage management and IT. &lt;A href="http://blogs.sas.com/content/iml/2013/08/02/how-old-is-your-version-of-sas-release-dates-for-sas-software.html" target="_self"&gt;SAS 9.2 is more than 8 years old &lt;/A&gt;and there have been seven releases of SAS since then. &amp;nbsp;In SAS/IML alone there have been about 50 new functions added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use one&amp;nbsp;DO loop and the LOC function t0 write your own BIN function. Then use the previous solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 10:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283727#M2900</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-07-12T10:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Re-code each element of a vector efficiently</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283729#M2901</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I am working a contractor so my weight is pretty low. &amp;nbsp;I've been informed plans for an upgrade are afoot, but it may be after I leave.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always thanks very much for the support.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 10:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Re-code-each-element-of-a-vector-efficiently/m-p/283729#M2901</guid>
      <dc:creator>Andrew_</dc:creator>
      <dc:date>2016-07-12T10:34:26Z</dc:date>
    </item>
  </channel>
</rss>

