<?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: Macro to look up last 4 digits in a table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761294#M240874</link>
    <description>I assure you using IN with the colon as I've shown does work so you're doing it wrong - or trying to do it in SQL, which you've never stated as a requirement. Did you try my example? Or Tom's? I believe Tom's is better and works for either SQL or DATA STEP but has a similar issue where you need to ensure the variable is at least the specified number of characters.</description>
    <pubDate>Thu, 12 Aug 2021 21:16:54 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-08-12T21:16:54Z</dc:date>
    <item>
      <title>Thank you</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761220#M240828</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 21:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761220#M240828</guid>
      <dc:creator>nancy_mancilla</dc:creator>
      <dc:date>2021-08-12T21:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761223#M240829</link>
      <description>&lt;P&gt;The SAS macro processor is a way to allow you to generate CODE.&lt;/P&gt;
&lt;P&gt;So what SAS code do you want to run?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type of variable is PRODUCT_ID?&lt;/P&gt;
&lt;P&gt;If it is a character variable then something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where product_id like '%889'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should work.&lt;/P&gt;
&lt;P&gt;If it is numeric then you want to do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where mod(product_id,1000) = 889&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What output do you want? What is the overall code you are trying to create?&lt;/P&gt;
&lt;P&gt;Why did you mention macro? Is there some part of the code that needs to change so that you want to use a macro or perhaps just a macro variable to generate that part of the code?&amp;nbsp; How does it change? What are the types of values that you will need to support?&amp;nbsp; How do the different values change how the SAS code you need to run looks?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 17:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761223#M240829</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-12T17:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761231#M240832</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 20:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761231#M240832</guid>
      <dc:creator>nancy_mancilla</dc:creator>
      <dc:date>2021-08-12T20:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761232#M240833</link>
      <description>Value to look up&lt;BR /&gt;8885&lt;BR /&gt;&lt;BR /&gt;Value expected&lt;BR /&gt;1274885&lt;BR /&gt;8841885</description>
      <pubDate>Thu, 12 Aug 2021 18:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761232#M240833</guid>
      <dc:creator>nancy_mancilla</dc:creator>
      <dc:date>2021-08-12T18:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761246#M240844</link>
      <description>Use the REVERSE and WHERE with colon operator? &lt;BR /&gt;REVERSE flips your variable around so you're comparing the start not the end. This allows you to use the colon operator which will truncate strings to check if they match. Note that if the string can be shorter this may not work as desired - test it with two digit product_ID for example. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;where reverse(product_ID) in: ('988', '211');&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Aug 2021 19:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761246#M240844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T19:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761247#M240845</link>
      <description>&lt;P&gt;Is that a typo or is that what you expect to match?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209066"&gt;@nancy_mancilla&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Value to look up&lt;BR /&gt;&lt;FONT size="4" color="#FF0000"&gt;&lt;STRONG&gt;8885&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;Value expected&lt;BR /&gt;1274&lt;FONT size="4" color="#800080"&gt;885&lt;/FONT&gt;&lt;BR /&gt;8841&lt;FONT size="4" color="#800080"&gt;885&lt;/FONT&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 19:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761247#M240845</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T19:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761251#M240848</link>
      <description>&lt;P&gt;I don't understand what your current code is doing. Why are you opening a dataset using macro code?&lt;/P&gt;
&lt;P&gt;Why are you generating multiple datasets?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to find observations where the last three characters are in a list of values just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where substrn(product_id,length(product_id)-2) in ('889' '123')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 19:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761251#M240848</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-12T19:41:55Z</dc:date>
    </item>
    <item>
      <title>Thanks!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761287#M240871</link>
      <description>&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 21:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761287#M240871</guid>
      <dc:creator>nancy_mancilla</dc:creator>
      <dc:date>2021-08-12T21:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761294#M240874</link>
      <description>I assure you using IN with the colon as I've shown does work so you're doing it wrong - or trying to do it in SQL, which you've never stated as a requirement. Did you try my example? Or Tom's? I believe Tom's is better and works for either SQL or DATA STEP but has a similar issue where you need to ensure the variable is at least the specified number of characters.</description>
      <pubDate>Thu, 12 Aug 2021 21:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761294#M240874</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T21:16:54Z</dc:date>
    </item>
    <item>
      <title>Thank you!!!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761298#M240878</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 21:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761298#M240878</guid>
      <dc:creator>nancy_mancilla</dc:creator>
      <dc:date>2021-08-12T21:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to look up last 4 digits in a table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761301#M240880</link>
      <description>Macros are not faster - they're faster for the programmer but typically operate slower as you have more code to generate. &lt;BR /&gt;A macro is not a good solution here.</description>
      <pubDate>Thu, 12 Aug 2021 21:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Thank-you/m-p/761301#M240880</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T21:36:20Z</dc:date>
    </item>
  </channel>
</rss>

