<?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: PROC SQL FIND in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69961#M20145</link>
    <description>It works if I use a literal string as the substring, so the folowing returns correctly;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL; &lt;BR /&gt;
CREATE TABLE BB As &lt;BR /&gt;
SELECT a.fname&lt;BR /&gt;
, a.lname&lt;BR /&gt;
, a.display_name&lt;BR /&gt;
, FIND( a.display_name , 'smit', 'i')&lt;BR /&gt;
&lt;BR /&gt;
FROM aa a&lt;BR /&gt;
; &lt;BR /&gt;
RESULT&lt;BR /&gt;
FNAME	LNAME	DISPLAY_NAME	_TEMA001&lt;BR /&gt;
Adam        Smith       Adam Smith            	6&lt;BR /&gt;
&lt;BR /&gt;
But does not work where the substring being searched for is a varaiable, as in &lt;BR /&gt;
&lt;BR /&gt;
 PROC SQL; &lt;BR /&gt;
CREATE TABLE BB As &lt;BR /&gt;
SELECT a.fname&lt;BR /&gt;
, a.lname&lt;BR /&gt;
, a.display_name&lt;BR /&gt;
, FIND( a.display_name , a.lname , 'i')&lt;BR /&gt;
&lt;BR /&gt;
FROM aa a&lt;BR /&gt;
; &lt;BR /&gt;
&lt;BR /&gt;
RESULT &lt;BR /&gt;
FNAME	LNAME	DISPLAY_NAME	_TEMA001&lt;BR /&gt;
Adam       Smith     	Adam Smith	0&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The reference for 'FIND' states: "substring &lt;BR /&gt;
is a character constant, &lt;B&gt;variable,&lt;/B&gt; or expression that specifies the substring of characters to search for in string."&lt;BR /&gt;
&lt;BR /&gt;
Which leads me to think that is can be used as in the second query, which should be finding the lname value 'Smith' in the display_name string 'Adam Smith'&lt;BR /&gt;
It doesnt, there is nothing in the log to report an error, the function just doesnt seem to work as described in Proc Sql? None of the similar character matching SAS functions will work with a variable as the substring either. &lt;BR /&gt;
For reference I am using EG as the query tool.</description>
    <pubDate>Mon, 19 Jan 2009 22:44:30 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-01-19T22:44:30Z</dc:date>
    <item>
      <title>PROC SQL FIND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69959#M20143</link>
      <description>I am trying to compare two variables with FIND.&lt;BR /&gt;
Should this work? It would seem despite the doco that the the substring needs to be a quoted litteral string?&lt;BR /&gt;
&lt;BR /&gt;
Sampel code&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL; &lt;BR /&gt;
CREATE TABLE BB As &lt;BR /&gt;
SELECT a.fname&lt;BR /&gt;
, a.lname&lt;BR /&gt;
, a.display_name&lt;BR /&gt;
, FIND( a.display_name , a.lname , 'i')&lt;BR /&gt;
&lt;BR /&gt;
FROM aa a&lt;BR /&gt;
;</description>
      <pubDate>Mon, 19 Jan 2009 05:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69959#M20143</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-19T05:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FIND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69960#M20144</link>
      <description>I got it to work. In what way does it not work for you? Maybe you should show your LOG/OUTPUT. My example from sashelp.class:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	select name, find(name,'ne','i')&lt;BR /&gt;
	from sashelp.class;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Partial output:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Name partialname findPos&lt;/B&gt; &lt;BR /&gt;
Alfred ne 0 &lt;BR /&gt;
Alice ne 0 &lt;BR /&gt;
Barbara ne 0 &lt;BR /&gt;
Carol ne 0 &lt;BR /&gt;
Henry ne 0 &lt;BR /&gt;
James ne 0 &lt;BR /&gt;
Jane ne 3 &lt;BR /&gt;
Janet ne 3 &lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Mon, 19 Jan 2009 12:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69960#M20144</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-01-19T12:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FIND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69961#M20145</link>
      <description>It works if I use a literal string as the substring, so the folowing returns correctly;&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL; &lt;BR /&gt;
CREATE TABLE BB As &lt;BR /&gt;
SELECT a.fname&lt;BR /&gt;
, a.lname&lt;BR /&gt;
, a.display_name&lt;BR /&gt;
, FIND( a.display_name , 'smit', 'i')&lt;BR /&gt;
&lt;BR /&gt;
FROM aa a&lt;BR /&gt;
; &lt;BR /&gt;
RESULT&lt;BR /&gt;
FNAME	LNAME	DISPLAY_NAME	_TEMA001&lt;BR /&gt;
Adam        Smith       Adam Smith            	6&lt;BR /&gt;
&lt;BR /&gt;
But does not work where the substring being searched for is a varaiable, as in &lt;BR /&gt;
&lt;BR /&gt;
 PROC SQL; &lt;BR /&gt;
CREATE TABLE BB As &lt;BR /&gt;
SELECT a.fname&lt;BR /&gt;
, a.lname&lt;BR /&gt;
, a.display_name&lt;BR /&gt;
, FIND( a.display_name , a.lname , 'i')&lt;BR /&gt;
&lt;BR /&gt;
FROM aa a&lt;BR /&gt;
; &lt;BR /&gt;
&lt;BR /&gt;
RESULT &lt;BR /&gt;
FNAME	LNAME	DISPLAY_NAME	_TEMA001&lt;BR /&gt;
Adam       Smith     	Adam Smith	0&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The reference for 'FIND' states: "substring &lt;BR /&gt;
is a character constant, &lt;B&gt;variable,&lt;/B&gt; or expression that specifies the substring of characters to search for in string."&lt;BR /&gt;
&lt;BR /&gt;
Which leads me to think that is can be used as in the second query, which should be finding the lname value 'Smith' in the display_name string 'Adam Smith'&lt;BR /&gt;
It doesnt, there is nothing in the log to report an error, the function just doesnt seem to work as described in Proc Sql? None of the similar character matching SAS functions will work with a variable as the substring either. &lt;BR /&gt;
For reference I am using EG as the query tool.</description>
      <pubDate>Mon, 19 Jan 2009 22:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69961#M20145</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-19T22:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FIND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69962#M20146</link>
      <description>Hi:&lt;BR /&gt;
  You might consider using the TRIM function around the variable string that you are searching for. Consider the program below. Without the TRIM function, the length of ALTPIECE is $8 and 'ne        ' is not found in anybody's name. SAS does not automatically trim trailing blanks for you in comparisons of this nature.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
                                    &lt;BR /&gt;
[pre]&lt;BR /&gt;
data class;&lt;BR /&gt;
  length wantpiece $2 altpiece $8;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  wantpiece = 'ne';&lt;BR /&gt;
  altpiece = 'ne';&lt;BR /&gt;
  fval = find(name,wantpiece,'i');&lt;BR /&gt;
  fval_alt = find(name,altpiece,'i');&lt;BR /&gt;
  fval3 = find(name,trim(altpiece),'i');&lt;BR /&gt;
run;&lt;BR /&gt;
                                    &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print data=class;&lt;BR /&gt;
  title 'from data step';&lt;BR /&gt;
  var wantpiece altpiece name fval fval_alt fval3;&lt;BR /&gt;
run;&lt;BR /&gt;
                                 &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select name, find(name,wantpiece,'i') as sfval,&lt;BR /&gt;
         find(name,altpiece,'i') as sfval_alt,&lt;BR /&gt;
         find(name,trim(altpiece),'i') as sfval3&lt;BR /&gt;
  from class;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 19 Jan 2009 23:20:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69962#M20146</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-01-19T23:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL FIND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69963#M20147</link>
      <description>Thank you Cynthia, that did it.</description>
      <pubDate>Mon, 19 Jan 2009 23:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-SQL-FIND/m-p/69963#M20147</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-01-19T23:31:45Z</dc:date>
    </item>
  </channel>
</rss>

