<?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 find a couple of words in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759949#M240251</link>
    <description>&lt;P&gt;I have a character column as follow:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;col1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1 ..(words in btw).. stage1.....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1...(words in btw)..stage2......&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2.(words in btw)...stage1....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2 .(words in btw)....stage2....&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;those dots between product names and stage names represent other words which doesn't matter to me. The product name and stage name can be anywhere in the string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My end goal is to create a new column as follow:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;col1&lt;/TD&gt;&lt;TD&gt;new_col&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1 ..(words in btw)...stage1.....&lt;/TD&gt;&lt;TD&gt;product1_stage1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1..(words in btw)...stage2......&lt;/TD&gt;&lt;TD&gt;product1_stage2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2..(words in btw)..stage1....&lt;/TD&gt;&lt;TD&gt;product2_stage1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2 ..(words in btw)...stage2....&lt;/TD&gt;&lt;TD&gt;product2_stage2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to write a code that looks at col1 and search for words "productX" and "stageZ" and if finds both then put new_col would be filled as "productX_stageZ", and the same for other products and stages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Aug 2021 14:47:59 GMT</pubDate>
    <dc:creator>Al_senior</dc:creator>
    <dc:date>2021-08-06T14:47:59Z</dc:date>
    <item>
      <title>find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759949#M240251</link>
      <description>&lt;P&gt;I have a character column as follow:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;col1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1 ..(words in btw).. stage1.....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1...(words in btw)..stage2......&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2.(words in btw)...stage1....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2 .(words in btw)....stage2....&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;those dots between product names and stage names represent other words which doesn't matter to me. The product name and stage name can be anywhere in the string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My end goal is to create a new column as follow:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;col1&lt;/TD&gt;&lt;TD&gt;new_col&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1 ..(words in btw)...stage1.....&lt;/TD&gt;&lt;TD&gt;product1_stage1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1..(words in btw)...stage2......&lt;/TD&gt;&lt;TD&gt;product1_stage2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2..(words in btw)..stage1....&lt;/TD&gt;&lt;TD&gt;product2_stage1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2 ..(words in btw)...stage2....&lt;/TD&gt;&lt;TD&gt;product2_stage2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I want to write a code that looks at col1 and search for words "productX" and "stageZ" and if finds both then put new_col would be filled as "productX_stageZ", and the same for other products and stages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 14:47:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759949#M240251</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-08-06T14:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759966#M240253</link>
      <description>Hi:&lt;BR /&gt;  This is hard to visualize given what you've posted. You say you only want "product1" and "stage1" but your end results shows "product2" and "stage2". Are the strings always consistent, IE, product1, product2, product3, product4 or are the products different names like wombat1, koala2, kangaroo3, eucalyptus4??? Same question for the "stage" string -- are the characters "stage" always in the string you're searching for. Providing data with just dots is misleading. You say that the product name and stage name can be anywhere in the string. Are there spaces in the string? Any delimiters that you can use for parsing. What code have you tried? How is the original data coming to you? Is it already in a SAS data set?&lt;BR /&gt;&lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 06 Aug 2021 14:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759966#M240253</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-08-06T14:43:03Z</dc:date>
    </item>
    <item>
      <title>conditional statement to find a word in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759967#M240272</link>
      <description>&lt;P&gt;I have a dataset as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;col1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1 ...(other words)......&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1....(other words)....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2....(other words)....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.....&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product120 ...(other words)...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I want to create a new column as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;col1&lt;/TD&gt;&lt;TD&gt;new_col&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1 .....(other words)....&lt;/TD&gt;&lt;TD&gt;product1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product1....(other words)....&lt;/TD&gt;&lt;TD&gt;product2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product2....(other words)....&lt;/TD&gt;&lt;TD&gt;product3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.....&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;product120 ...(other words)...&lt;/TD&gt;&lt;TD&gt;product120&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'd like to do is to write a conditional statement that if the word "productX" was in the string then it puts "productX" in the new column. The word product could be anywhere in the string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 14:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759967#M240272</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-08-06T14:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759968#M240255</link>
      <description>Product1 was just an example. I edited my post and generalized it to ProductX and StageZ.</description>
      <pubDate>Fri, 06 Aug 2021 14:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759968#M240255</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-08-06T14:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759972#M240258</link>
      <description>Hi:&lt;BR /&gt;  You didn't answer my question. Do the products ALWAYS contain the letters P-R-O-D-U-C-T followed by either a number or a letter? Does the string for stages ALWAYS contain the letters S-T-A-G-E followed by either a number or a letter? Can the PRODUCT or the STAGE be followed by more than one number or letter:&lt;BR /&gt;Product11&lt;BR /&gt;Product222&lt;BR /&gt;ProductABC&lt;BR /&gt;StageX1&lt;BR /&gt;Stage2234&lt;BR /&gt;Stage-54&lt;BR /&gt;&lt;BR /&gt;  Do you have real data the shows the "words in btw"? What is the maximum length of the original COL1 string? What is the maximum length of the value of PRODUCT or STAGE in the string?? 8 characters,15 characters? Is it always Product1, product1 (without spaces in the string) or is it Product 1, and Product X? &lt;BR /&gt;&lt;BR /&gt;What code have you tried?&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;BR /&gt;  I</description>
      <pubDate>Fri, 06 Aug 2021 14:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759972#M240258</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-08-06T14:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759977#M240260</link>
      <description>&lt;P&gt;Strong suggestion: Create TWO new variables. One for the product, other for the stage.&lt;/P&gt;
&lt;P&gt;I don't know what you may envision doing but multiple values in a single variable almost invariably adds lots of extra work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider that you want to to a summary count based on Product values. If the value is Product1_Stage1 or Product1_Stage2 that means you have to do something else to get just the product, otherwise every product will be duplicated with each level of stage. So save some headaches and split them up now. Or provide a real good use case for how you intend to use the combined value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, just where do the actual Product names that you want reside? Your statement " The product name and stage name can be anywhere in the string." means that we have no clue what you are looking for and can't parse what you show as it is basically meaningless. The actual "product" could very well be in the (words in btw) as far as we know. So how do you expect to tell a program what specific products you are looking for? There is a change if the verbiage actually is "Stage" that something could be done with that but that is rife with potential other words like "stage manager" "stage lights" or similar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW your example data strongly implies that Product is always at the beginning of the variable and&amp;nbsp; that does not match your "anywhere in the string" description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typical "find" of specific words in a string involve, strangely enough, a function named FINDW (for Find word), to identify the location and then use a function such as SCAN or SUBSTR to extract the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 15:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759977#M240260</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-06T15:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759982#M240264</link>
      <description>Product names are different, like what you mentioned as wombat, koala, kangaroo, eucalyptus4. And the product name most of the time follows by a number but not always. It is the same story for stage. Stages have different names.&lt;BR /&gt;And yeas, there are spaces in the string.&lt;BR /&gt;The data is a SAS Table.&lt;BR /&gt;There is not specific character that I can use to parse the string.&lt;BR /&gt;What I tried so far was creating a new column for each product as:&lt;BR /&gt;&lt;BR /&gt;indicator = index(col1, "productX")&lt;BR /&gt;if indicator gt 0 then product_col = "productX"&lt;BR /&gt;&lt;BR /&gt;which obviously is an awful solution if there many product names.</description>
      <pubDate>Fri, 06 Aug 2021 15:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759982#M240264</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-08-06T15:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759988#M240268</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/387876"&gt;@Al_senior&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Product names are different, like what you mentioned as wombat, koala, kangaroo, eucalyptus4. And the product name most of the time follows by a number but not always. It is the same story for stage. Stages have different names.&lt;BR /&gt;And yeas, there are spaces in the string.&lt;BR /&gt;The data is a SAS Table.&lt;BR /&gt;There is not specific character that I can use to parse the string.&lt;BR /&gt;What I tried so far was creating a new column for each product as:&lt;BR /&gt;&lt;BR /&gt;indicator = index(col1, "productX")&lt;BR /&gt;if indicator gt 0 then product_col = "productX"&lt;BR /&gt;&lt;BR /&gt;which obviously is an awful solution if there many product names.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Still not saying where the actual values of product or stage comes from. Are they in another data set? Macro variable? or what? How many of each are there? Are there restrictions that some stages only appear with some products?&lt;/P&gt;
&lt;P&gt;And a truly nasty possible headache causer: do any of the products or stages appear more than once in a given value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 15:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759988#M240268</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-06T15:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759991#M240269</link>
      <description>&lt;P&gt;This is the best that I have, but I think it really depends on your data. If you're not familiar with regular expressions (I am a bit of a beginner/intermediate), I strongly consider learning about them to deal with weird parsing issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input col1 $50.;
datalines;
product1..... stage1.....
product1.....stage2......
product2....stage1....
product2 .....stage2....
;
run;

data want;
	set have;
		words = prxchange("s/[^(product\d{1}|stage\d{1})]//i", -1, col1);
		join_location = prxmatch("/\d{1}\w{1}/", words);
		new_col = catx("_", substr(words, 1, join_location), substr(words, join_location + 1, length(words)));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;col1 	words 	join_location 	new_col
product1..... stage1..... 	product1stage1 	8 	product1_stage1
product1.....stage2...... 	product1stage2 	8 	product1_stage2
product2....stage1.... 	product2stage1 	8 	product2_stage1
product2 .....stage2.... 	product2stage2 	8 	product2_stage2&lt;/PRE&gt;
&lt;P&gt;I don't have enough of your data to know for sure if that's what you need or will solve your issue, but it seems to match your have example.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 15:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759991#M240269</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-08-06T15:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement to find a word in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759998#M240273</link>
      <description>&lt;P&gt;Duplicate post moved to this thread.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 15:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/759998#M240273</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-06T15:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760000#M240274</link>
      <description>&lt;P&gt;Can you show us actual data?&amp;nbsp; If the data is confidential somehow, then you can substitute&amp;nbsp;wombat, koala, kangaroo, eucalyptus, etc. for the parts that are confidential.&amp;nbsp; Otherwise, I don't think we have a clear idea of what it is that you're looking for, and it's going to be really difficult for us to help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 15:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760000#M240274</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-06T15:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760023#M240287</link>
      <description>&lt;P&gt;My data is confidential so I go with an example of car manufacturing which could be similar to the following table:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Col1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Camry red Manual&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Corolla Blue Automatic&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Camry Blue (Japan) - Manual&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Prius (America) Toyota Automatic&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I want to get a table as bellow:&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Col1&lt;/TD&gt;&lt;TD&gt;new_col&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Camry red Manual&lt;/TD&gt;&lt;TD&gt;Camry Manual&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Corolla Blue Automatic&lt;/TD&gt;&lt;TD&gt;Corolla Automatic&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Civic Blue (Japan) - Manual&lt;/TD&gt;&lt;TD&gt;Civic Manual&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Prius (America) - Toyota Automatic&lt;/TD&gt;&lt;TD&gt;Prius Automatic&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the following code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data want;
set have;
car= index(Col1, "Automatic");
if car gt 0 then type= "Automatic";
else type="Manual";
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now I think if I can create a column named &lt;STRONG&gt;CAR&lt;/STRONG&gt; with the following logic (please pay attention it is not the code, it is just the logic)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if "Camry" is&amp;nbsp; in Col1 &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then CAR = "Camry"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;else if "Corolla" is in Col1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then CAR="Corolla"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;else if "Prius" is in Col1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;then CAR="Prius"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;else if "Civic" in Col1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then CAR="Civic"&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so if someone can help me with this if statement I guess that could be the solution for my problem.&lt;/P&gt;&lt;P&gt;And finally when I have column "CAR" and column "Type" I can combine them as the new column that I am looking for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 17:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760023#M240287</guid>
      <dc:creator>Al_senior</dc:creator>
      <dc:date>2021-08-06T17:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760029#M240289</link>
      <description>&lt;P&gt;Hi:&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp; With data as you show above, the program doesn't need an IF statement.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1628270950906.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62346i88AFE5EFFE965DBF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1628270950906.png" alt="Cynthia_sas_0-1628270950906.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if the data are more complex, then the solution will be more complex.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 17:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760029#M240289</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-08-06T17:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760061#M240295</link>
      <description>&lt;P&gt;OK, I think I might have something for you.&amp;nbsp; Below is some SAS code.&amp;nbsp; Below the code are the results.&amp;nbsp; This code will parse out the values you're looking for no matter the word order and no matter placement.&amp;nbsp; In other words if the type of car (automatic vs. manual) comes before the model of the car (Prius, Camry, etc.), it would still be picked up.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code requires that you define a table of the cars (or whatever it really is) that you're looking for as well as the possible types and then does a double array search of each line of data.&amp;nbsp; Note that if a definition is omitted, e.g. the Volt, "unknown" will be returned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;IMPORTANT:&amp;nbsp;&lt;/STRONG&gt;This code does not allow embedded blanks.&amp;nbsp; If you wanted, for example "Accord LX", you would need to code "Accord_LX"&amp;nbsp; (or "Accord-LX") in your both data and in your table definitions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See what you think.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Have;
	INFILE	DATALINES	TRUNCOVER;
	INPUT
		Data_To_Examine	$CHAR128.;
		;
DATALINES;
Camry red Manual
Corolla Blue Automatic
Yugo (Yugoslavia) Manual
Tiguan Germany Automatic
Camry Blue (Japan) - Manual
Prius (America) Toyota Automatic
Volt (US) Automatic
Blue Automatic Honda Civic 4-Door
Gray Manual Accord LX 2012
;
RUN;

DATA	Cars_Table;
	INFILE	DATALINES	TRUNCOVER;
	INPUT
		Car	$CHAR32.;
		;
DATALINES;
Camry
Corolla
Prius
Accord
Civic
;
RUN;

PROC	SQL	NOPRINT;
	SELECT	COUNT(Car)
		INTO	:	Car_Count	TRIMMED
			FROM	Cars_Table;
QUIT;
%PUT	NOTE:  &amp;amp;=Car_Count;

PROC	TRANSPOSE	DATA=Cars_Table
					OUT	=Cars_Array	(DROP=_:)
					Prefix=Car_
					;
	Var	Car;
RUN;

DATA	Types_Table;
	INFILE	DATALINES	TRUNCOVER;
	INPUT
		Type	$CHAR32.;
		;
DATALINES;
Automatic
Manual
;	
RUN;

PROC	SQL	NOPRINT;
	SELECT	COUNT(Type)
		INTO	:	Type_Count	TRIMMED
			FROM	Types_Table;
QUIT;
%PUT	NOTE:  &amp;amp;=Type_Count;

PROC	TRANSPOSE	DATA=Types_Table
					OUT	=Types_Array	(DROP=_:)
					Prefix=Type_
					;
	Var	Type;
RUN;

DATA	Want;
	DROP	_:;
	DROP	Car_1	-	Car_&amp;amp;Car_Count;
	DROP	Type_1	-	Type_&amp;amp;Type_Count;

	IF	_N_								=	1										THEN
		DO;
			SET	Cars_Array;
			SET	Types_Array;
		END;
	ARRAY	Cars	{&amp;amp;Car_Count}	$32	Car_1	-	Car_&amp;amp;Car_Count;
	ARRAY	Types	{&amp;amp;Type_Count}	$32	Type_1	-	Type_&amp;amp;Type_Count;

	SET		Have;

	LENGTH	Car_Var		$32;
	LENGTH	Type_Var	$32;

	Car_Var								=	'Unknown';
	Type_Var							=	'Unknown';

	DO	_i								=	1	TO	&amp;amp;Car_Count;
		IF	INDEX(UPCASE(Data_To_Examine), UPCASE(STRIP(Cars{_i})))					THEN
			DO;
				Car_Var					=	Cars{_i};
				DO	_j					=	1	TO	&amp;amp;Type_Count;
					IF	INDEX(UPCASE(Data_To_Examine), UPCASE(STRIP(Types{_j})))	THEN
						DO;
							Type_Var	=	Types{_j};
						END;
				END;
			END;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1628274452578.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62360i8DD678199C3FA774/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1628274452578.png" alt="jimbarbour_0-1628274452578.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 18:29:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760061#M240295</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-06T18:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: find a couple of words in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760068#M240299</link>
      <description>&lt;P&gt;IF you are going to type in literal strings to look for then a temporary array is one way to do this.&lt;/P&gt;
&lt;PRE&gt;DATA	Have;
	INFILE	DATALINES	TRUNCOVER;
	INPUT
		Col1 $CHAR128.;
		;
DATALINES;
Camry red Manual
Corolla Blue Automatic
Yugo (Yugoslavia) Manual
Tiguan Germany Automatic
Camry Blue (Japan) - Manual
Prius (America) Toyota Automatic
Volt (US) Automatic
Blue Automatic Honda Civic 4-Door
Gray Manual Accord LX 2012
;
RUN;

data example;
   set have;
   length car $ 20;
   /* left out Volt to show how that the name must be in the temporary array to be found
       and added a value not in the data to show that have a value to search for not present
       does not cause problems
   */
   array p(8) $ 20 _temporary_ ("Camry","Corolla","Yugo","Tiguan","Prius","Civic","Accord","Not_in_data");
   do i=1 to dim(p);
     if find(col1, trim(p[i]),'i')&amp;gt;0 then do;
        Car=p[i];
        leave; /* this assumes only expect/want to find one car value in col1*/
     end;
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;Note: SAS does have an IN operator but it is the equivalent of a bunch of : if var=value1 or var=value2 or var=value3 ....&lt;/P&gt;
&lt;P&gt;Not the way your hopefully pseudo code was intended to work. Presence of a string in another is the work for Index, Indexw, Find, of Findw generally.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exercise for the interested reader is to make a second temporary array for the "stage" equivalent text.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 19:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-a-couple-of-words-in-a-string/m-p/760068#M240299</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-06T19:12:20Z</dc:date>
    </item>
  </channel>
</rss>

