<?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: How can I find if data in one variable does exist in another variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932060#M366670</link>
    <description>&lt;P&gt;Didn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results (at least for a sample). Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Warning:&lt;/STRONG&gt; This forum seriously reformats text pasted into the main message windows. It will replace consecutive spaces with one (sometimes) other "white space" characters such as tabs as well. So any text you want to use for tests in string comparisons should be pasted into a text box. Really.&lt;/P&gt;
&lt;P&gt;Code as well as sometimes strange non-printable characters appear that will prevent code from running correctly or at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try adding STRIP(CITY) when using that as the search.&lt;/P&gt;
&lt;PRE&gt;data work.MATCHING_CITY;
    set work.ADDR_DATA; 
    if index(FULL_ADDRESS, strip(CITY) ) &amp;gt; 0 then do;
       output;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;The behavior of INDEX, and most of the other string comparison functions, is that a variable will be padded with blanks to its defined length. Which means they are often way too long to find the target value in the source.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2024 21:19:21 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-06-12T21:19:21Z</dc:date>
    <item>
      <title>How can I find if data in one variable does exist in another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932059#M366669</link>
      <description>&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;Var 1 as full_address '123 ABC STEET APT 305 MINNEAPOLIS MN 55332' and '333 5TH ST #3 SAINT PAUL 55343'&lt;/P&gt;&lt;P&gt;Var 2 as city 'EDINA' and 'SAINT PAUL'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if city exist in full_address, output the result&lt;/P&gt;&lt;P&gt;Below are few codes I tried didn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data MATCHING_CITY;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set ADDR_DATA;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if index(FULL_ADDRESS, CITY) &amp;gt; 0 then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;output;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;data MATCHING_CITY;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set ADDR_DATA;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if find(FULL_ADDRESS, CITY) &amp;gt; 0 then do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;output;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;data MATCHING_CITY;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set ADDR_DATA;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;/*Initialize match flag*/&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;Match_flag = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; /* Iterate through each city in CITY */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; do i = 1 to countw(CITY, ' ');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; home_city = scan(CITY, i, ' ');&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Check if home_city exists within cactus_ben_nm_addr_comb_cpr */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if findw(FULL_ADDRESS, home_city, ' ', 'i') &amp;gt; 0 then do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* Match found */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Match_flag=1;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;leave;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; drop home_city i; /* Drop temporary variables */&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;before I proceed these code I already, trim, upcase, compbl, compress the data.&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Jun 2024 21:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932059#M366669</guid>
      <dc:creator>kojuramesh</dc:creator>
      <dc:date>2024-06-12T21:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I find if data in one variable does exist in another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932060#M366670</link>
      <description>&lt;P&gt;Didn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results (at least for a sample). Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Warning:&lt;/STRONG&gt; This forum seriously reformats text pasted into the main message windows. It will replace consecutive spaces with one (sometimes) other "white space" characters such as tabs as well. So any text you want to use for tests in string comparisons should be pasted into a text box. Really.&lt;/P&gt;
&lt;P&gt;Code as well as sometimes strange non-printable characters appear that will prevent code from running correctly or at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try adding STRIP(CITY) when using that as the search.&lt;/P&gt;
&lt;PRE&gt;data work.MATCHING_CITY;
    set work.ADDR_DATA; 
    if index(FULL_ADDRESS, strip(CITY) ) &amp;gt; 0 then do;
       output;
    end;
run;&lt;/PRE&gt;
&lt;P&gt;The behavior of INDEX, and most of the other string comparison functions, is that a variable will be padded with blanks to its defined length. Which means they are often way too long to find the target value in the source.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 21:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932060#M366670</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-12T21:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I find if data in one variable does exist in another variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932066#M366675</link>
      <description>Thank you for prompt answer, I added strip and code seems working now.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 12 Jun 2024 21:44:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-find-if-data-in-one-variable-does-exist-in-another/m-p/932066#M366675</guid>
      <dc:creator>kojuramesh</dc:creator>
      <dc:date>2024-06-12T21:44:37Z</dc:date>
    </item>
  </channel>
</rss>

