<?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: Selecting observations from character variable that contain specific string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637487#M189481</link>
    <description>&lt;P&gt;Thanks! The find function with upcase didn't work for some reason. It only selected observations with lower case 'or'.&lt;/P&gt;</description>
    <pubDate>Sat, 04 Apr 2020 02:50:01 GMT</pubDate>
    <dc:creator>Caetreviop543</dc:creator>
    <dc:date>2020-04-04T02:50:01Z</dc:date>
    <item>
      <title>Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637371#M189464</link>
      <description>&lt;P&gt;I have a character variable that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;Var1&lt;/STRONG&gt;&lt;BR /&gt;Order1&lt;BR /&gt;order2 OR order 3&lt;BR /&gt;Something else&lt;BR /&gt;Order3 or Order5&lt;BR /&gt;Text3&lt;BR /&gt;Order4 Or Order8&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I select just the observations that contain 'or' in the middle of the text string, which could between two, three, or four words? Moreover, is there a way for it not to be case sensitive? I tried proc sql:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select * from data 
where var1 like '%OR%' or var1 like '%or%'
or var1 like '%Or%;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But that includes records which have the word 'Order', which I don't want. I thought maybe SAS would recognize the Or if I put a space around it:&lt;/P&gt;&lt;PRE&gt;proc sql;
select * from data
where var1 like '% OR %' or var1 like '% or %'
or var1 like '% Or %';
quit;&lt;/PRE&gt;&lt;P&gt;But it doesn't. I really don't want to write the text out in full, because it's very long. I appreciate any help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 22:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637371#M189464</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2020-04-03T22:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637375#M189467</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input Var1 $30.;
cards;
Order1
order2 OR order 3
Something else
Order3 or Order5
Text3
Order4 Or Order8
;

data want;
 set have;
 if upcase(scan(var1,int(median(1,countw(var1,' '))),' '))='OR' then output;
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;Var1&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;order2 OR order 3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Order3 or Order5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Order4 Or Order8&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Apr 2020 22:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637375#M189467</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-03T22:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637376#M189468</link>
      <description>&lt;P&gt;I believe you just need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where find(upcase(var1),' OR ')
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 22:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637376#M189468</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2020-04-03T22:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637377#M189469</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 want=upcase(scan(var1,int(median(1,countw(var1,' '))),' '));
 if want='OR';
run;
proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;Var1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;want&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;order2 OR order 3&lt;/TD&gt;
&lt;TD class="l data"&gt;OR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Order3 or Order5&lt;/TD&gt;
&lt;TD class="l data"&gt;OR&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Order4 Or Order8&lt;/TD&gt;
&lt;TD class="l data"&gt;OR&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Apr 2020 22:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637377#M189469</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-03T22:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637378#M189470</link>
      <description>&lt;P&gt;Try regular expression matching:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where prxmatch("/\w\s+or\s+\w/i", var1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note : The "i" makes the match case insensitive.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 22:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637378#M189470</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-04-03T22:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637463#M189471</link>
      <description>&lt;P&gt;Use the find function, works in data step or sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 if find(upcase(var),' OR ');  /* OR has a blank before and after in quotes */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Apr 2020 22:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637463#M189471</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-04-03T22:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637478#M189478</link>
      <description>&lt;P&gt;Why didn't the version with the spaces work?&lt;/P&gt;
&lt;P&gt;Anyway use INDEXW() or FINDW() if you only want to match full words.&lt;/P&gt;
&lt;P&gt;Use UPCASE() function or the i modifier of the FINDW() function if you want to match OR, or, Or or oR.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2020 00:35:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637478#M189478</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-04T00:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations from character variable that contain specific string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637487#M189481</link>
      <description>&lt;P&gt;Thanks! The find function with upcase didn't work for some reason. It only selected observations with lower case 'or'.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2020 02:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations-from-character-variable-that-contain/m-p/637487#M189481</guid>
      <dc:creator>Caetreviop543</dc:creator>
      <dc:date>2020-04-04T02:50:01Z</dc:date>
    </item>
  </channel>
</rss>

