<?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 Merge , finding listed variables within large text strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/572046#M161418</link>
    <description>&lt;P&gt;PGS,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much, specifications are made to be broken, especially my poorly written ones (!),&lt;/P&gt;&lt;P&gt;thanks for providing an understandable solution.&lt;/P&gt;&lt;P&gt;R&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2019 13:50:40 GMT</pubDate>
    <dc:creator>rmacarthur</dc:creator>
    <dc:date>2019-07-09T13:50:40Z</dc:date>
    <item>
      <title>PROC SQL Merge , finding listed variables within large text strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/571932#M161361</link>
      <description>&lt;P&gt;Hi SAS Friends,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need some help with a Proc SQL merge, believe this is a "many to many" merge.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is the sample code and desired output, have also pasted it below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data COLORS; 
   	input 		color $10.		; 
	datalines					;
red
purple
green
blue
;
run; 

data	Storys	;
	input	ID	$2.  Fruit_Storys $45.	;
	datalines						;
1	red delicious apples are the prode of NY	
2	the sweet fuscia parsimmons are too ripe 	
3	yellow and blue gala apples are superb	    
4	granny apples are green and lean	
5	sour grey raisins are never chosen	    
:
run	;


/*...DESIRED OUTPUT...*/
ID	Fruit_Storys								color
1	red delicious apples are the prode of NY	red
3	yellow and blue gala apples are superb	    blue
4	granny apples are green and lean			green&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What needs to happen is that in the STORYS data set, for the variable "Fruit_Storys" , the listed substrings from the COLORS data set variable :color" are searched for.&amp;nbsp; If not present the row is ignored.&amp;nbsp; If one of the color variables is present the row is retained, and also in the output the identified "colors" variable is listed in the column "color" .&amp;nbsp; Also the ID variable from the&amp;nbsp;&amp;nbsp;"Fruit_Storys" data set is carried along.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suppose this is a &lt;EM&gt;walk in the park&amp;nbsp;&lt;/EM&gt;for an experienced PROC SQL maven, and would greatly appreciate an answer with functional code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks as always, much appreciated&amp;nbsp;&lt;/P&gt;&lt;P&gt;Robert&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 01:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/571932#M161361</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2019-07-09T01:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Merge , finding listed variables within large text strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/571947#M161371</link>
      <description>&lt;P&gt;What spoils a walk in the park is an incomplete problem specification &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;. In the case where more than one color appears in the string (ID=6), I cloose to report the last occurence:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data COLORS; 
   	input color $10. ; 
	datalines;
red
purple
green
blue
;

data	Storys	;
	input ID $2. Fruit_Storys $64.;
	datalines						;
1	red delicious apples are the prode of NY	
2	the sweet fuscia parsimmons are too ripe 	
3	yellow and blue gala apples are superb	    
4	granny apples are green and lean	
5	sour grey raisins are never chosen	    
6	sour green or blue raisins are sometimes chosen	    
;

proc sql;
create table matches as
select
    ID,
    fruit_storys,
    color,
    findw(fruit_storys, trim(color)) as pos
from 
    storys, colors 
where calculated pos &amp;gt; 0
group by ID, fruit_storys
having calculated pos = max(calculated pos);
quit;
 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 03:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/571947#M161371</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-07-09T03:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Merge , finding listed variables within large text strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/572046#M161418</link>
      <description>&lt;P&gt;PGS,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks very much, specifications are made to be broken, especially my poorly written ones (!),&lt;/P&gt;&lt;P&gt;thanks for providing an understandable solution.&lt;/P&gt;&lt;P&gt;R&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 13:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Merge-finding-listed-variables-within-large-text/m-p/572046#M161418</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2019-07-09T13:50:40Z</dc:date>
    </item>
  </channel>
</rss>

