<?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: find multiple occurrences of a value in a text string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437802#M109094</link>
    <description>&lt;P&gt;Yes, INDEX is a good tool for the job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if index(race, 'White') then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, note that you can only have one value for SORD per observation.&amp;nbsp; So your logic is selecting which RACE value takes priority.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Feb 2018 22:11:32 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-15T22:11:32Z</dc:date>
    <item>
      <title>find multiple occurrences of a value in a text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437797#M109091</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a race text variable that can have multiple values for race:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RACE&lt;/P&gt;
&lt;P&gt;Asian, White&lt;/P&gt;
&lt;P&gt;White&lt;/P&gt;
&lt;P&gt;Black, White&lt;/P&gt;
&lt;P&gt;Asian, Black&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I use a find all occurrences of say, Asian, and assign a numeric value?&amp;nbsp; I know it is not using 'contains' but this is an example of what I'm trying to do.&amp;nbsp; Maybe index?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if c then do;&lt;BR /&gt; ord=1;&lt;BR /&gt; if race contains ('White') then sord=6;&lt;BR /&gt; else if race contains ('Black') then sord=4;&lt;BR /&gt; else if race contains ('Asian') then sord=3;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 21:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437797#M109091</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-02-15T21:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: find multiple occurrences of a value in a text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437802#M109094</link>
      <description>&lt;P&gt;Yes, INDEX is a good tool for the job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if index(race, 'White') then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, note that you can only have one value for SORD per observation.&amp;nbsp; So your logic is selecting which RACE value takes priority.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 22:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437802#M109094</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-15T22:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: find multiple occurrences of a value in a text string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437818#M109098</link>
      <description>&lt;P&gt;And perhaps anything with a comma could/should be treated as "more than one race"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For one project where I have stuff like this I actually create a series of dichotomous variables such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rw&amp;nbsp;= index(Race,'White')&amp;gt;0;&lt;/P&gt;
&lt;P&gt;rb&amp;nbsp;= index(Race,'Black')&amp;gt;0;&lt;/P&gt;
&lt;P&gt;ra&amp;nbsp;= index(Race,'Asian')&amp;gt;0;&lt;/P&gt;
&lt;P&gt;/* and for those who think Hispanic is a race*/&lt;/P&gt;
&lt;P&gt;rh = index(Race,'Hispanic)&amp;gt;0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because I have to report on multiracial, those that are only one race or that report combinations.&lt;/P&gt;
&lt;P&gt;sums or max of multiple variables are then easy ways to find the specific examples.&lt;/P&gt;
&lt;P&gt;HB = sum(rb,rh)=2; for instance creates a dichotomous variable indicating Black Hispanics. Which is much easier once you get used to it than: IF&amp;nbsp;rb and rh then HB=1; else HB=0;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 23:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-multiple-occurrences-of-a-value-in-a-text-string/m-p/437818#M109098</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-15T23:20:27Z</dc:date>
    </item>
  </channel>
</rss>

