<?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: If/where contains problem while merging in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85067#M24325</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As I said to mkeintz this is a 3 dataset merge &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw I haven't tried with your method yet, but sure thing is I'll give it a try anyway &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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help &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;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Aug 2012 22:27:37 GMT</pubDate>
    <dc:creator>Way2go</dc:creator>
    <dc:date>2012-08-06T22:27:37Z</dc:date>
    <item>
      <title>If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85062#M24320</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello! I have to perform a task in SAS but I don't know how to do &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; I've already searched in the forums but I couldn't find anything. I hope you can help me &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say you are merging 2 data set and some of the variables are: ITEM_description (string), producer (string) and brand (string) but the last 2 have missing values. Your goal is to put a value (string) to producer and brand that depends on ITEM_description. I'll make an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pdv - ITEM_desc&amp;nbsp; -&amp;nbsp; producer - brand&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;12&amp;nbsp; - Nutella 500g - (missing) - (missing) &lt;/P&gt;&lt;P&gt;76&amp;nbsp; - Nutella 750g - (missing) - (missing)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data C;&lt;/P&gt;&lt;P&gt;merge A B;&lt;/P&gt;&lt;P&gt;by pdv;&lt;/P&gt;&lt;P&gt;where ITEM_desc CONTAINS Nutella then do;&lt;/P&gt;&lt;P&gt;producer=Ferrero;&lt;/P&gt;&lt;P&gt;brand=Nutella;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I know that WHERE doesn't work with THEN and DO but IF doesn't work with CONTAINS (that is the operator I need). How should I write the syntax to make it work? Thank you in advance &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 13:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85062#M24320</guid>
      <dc:creator>Way2go</dc:creator>
      <dc:date>2012-08-06T13:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85063#M24321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suggest you look into the character functions available in SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect:&lt;/P&gt;&lt;P&gt;&amp;nbsp; if findw(ITEM_desc,"Nutella") then do ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;could give you what you want.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Hopefully this is a one-to-one merge.&amp;nbsp; If not, you can run into surprises because PRODUCER and BRAND will be retained across iterations of the datastep.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;--Q.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 13:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85063#M24321</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2012-08-06T13:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85064#M24322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alternatively, if the string you are searching for might contain additional characters before or after it (i.e., it isn't necessarily a word), you could use the index function.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; informat item_desc $30.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input pdv ITEM_desc&amp;nbsp; (producer brand) ($);&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards; &lt;/P&gt;&lt;P&gt;12&amp;nbsp; Nutella 500g&amp;nbsp; .&lt;/P&gt;&lt;P&gt;76&amp;nbsp; Nutella 750g&amp;nbsp; .&lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;data b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input pdv price;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards; &lt;/P&gt;&lt;P&gt;12&amp;nbsp; 2.5&lt;/P&gt;&lt;P&gt;76&amp;nbsp; 3.0&lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;data C;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge A B;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by pdv;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if index(ITEM_desc,'Nutella') then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; producer='Ferrero';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; brand='Nutella';&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 13:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85064#M24322</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-06T13:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85065#M24323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Waytogo:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You are merging data sets A and B by pdv, which means that for a given PDV, the value ot item_desc, producer, and brand in B will overwrite the values in A,&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt; even when the B values are missing&lt;/STRONG&gt;&lt;/SPAN&gt;.&amp;nbsp; Is that what you want?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As to your question, you could replace the "where ... contains" expression with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index(item_desc,'Nutella') &amp;gt; 0 then do; ... ...&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The index function returns the leftmost position in ITEM_DESC of the text "Nutella".&amp;nbsp; If "Nutella" is not in item_desc, then the index functions yields a zero.&amp;nbsp; BTW, can you be certain the text your are looking for will have precisely the mixed cases "Nutella"?&amp;nbsp; If not then you might want to modify to&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if index(upcase(item_desc,'NUTELLA')&amp;gt;0 then do; ... ... end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I take it that you accidentally forgot to quote "Nutella", because left unquoted, SAS looks for a variable named nutella rather than the literall text.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Also, here's the SAS 9.2 web page of functions, orgainized by category: &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245852.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245852.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245852.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 13:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85065#M24323</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2012-08-06T13:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85066#M24324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually is a 3 dataset merge where item_descr producer and brand appear in different datasets, so there isn't the overwriting issue! (I said that i only had 2 datasets A and B just to simplify the question)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway I have tried this &lt;EM&gt;if index(item_desc,'Nutella') &amp;gt; 0 then do; ... ...&amp;nbsp; end;&lt;/EM&gt; and it works!&amp;nbsp; Also you supposed right: the text in item_descr is all in uppercase but I didn't need to use this &lt;EM&gt;if index(upcase(item_desc,'NUTELLA')&amp;gt;0 then do; ... ... end;&lt;/EM&gt; because it worked in the first way.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 22:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85066#M24324</guid>
      <dc:creator>Way2go</dc:creator>
      <dc:date>2012-08-06T22:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85067#M24325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As I said to mkeintz this is a 3 dataset merge &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw I haven't tried with your method yet, but sure thing is I'll give it a try anyway &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;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help &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;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 22:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85067#M24325</guid>
      <dc:creator>Way2go</dc:creator>
      <dc:date>2012-08-06T22:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: If/where contains problem while merging</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85068#M24326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help too :smileygrin: Very helpful indeed &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt; In fact I used the index function!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Aug 2012 22:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-where-contains-problem-while-merging/m-p/85068#M24326</guid>
      <dc:creator>Way2go</dc:creator>
      <dc:date>2012-08-06T22:31:19Z</dc:date>
    </item>
  </channel>
</rss>

