<?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: finding a text in various columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755159#M238258</link>
    <description>&lt;P&gt;You don't want INDEXC.&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;P class="xis-shortDescription"&gt;Indexc Searches a character expression for any of the specified characters, and returns the position of that character.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;So in this example:&lt;/P&gt;
&lt;PRE&gt;data junk;
   input word $;
   pos = indexc(word,'hep');
datalines;
p
ah
ace
;
&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;you get Pos values of 1, because there is a p in the first position in the first value of word, 2 because h is the second letter in the second value and 3 because e is the third letter in word on the observation. ANY of the characters.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;If you want to find the entire string HEP then you need to use one of Index, Indexw, Find or Findw. And as in your other post the things like case consideration and presence as a substring in other words is critical.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;It is best to provide some example values of your variable and what you expect the result to look like.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;And for consistency sake on my part, I strongly suggest that you use 1/0 numeric coding instead of 'yes' 'no' text coding.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;Later when you want to do summaries you can get the number of yes by using the SUM , the percent yes with the Mean statistics in any of multiple procedures. Max =1 tells you if that at least one value is 1, Max=0 tells you none are 1, Range=0 tells you all are the same value. A bit trickier to get such things with 'yes' / 'no'.&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 19 Jul 2021 23:29:36 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-07-19T23:29:36Z</dc:date>
    <item>
      <title>finding a text in various columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755141#M238245</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;I have a very large data set of about 10,000 observations and 140 variables varying in numbers and characters. I am trying to find how many time Hep B is mentioned in the data set. Basically trying to quantify doctor's notes, This could show up as "hepatitis B","HepB" "HBsAG negative"&amp;nbsp;"HBsAG positive" etc. I only need the rows associated with people who have been tested for Hep B, but it could be mentioned in different columns such as "remarks" or "tests"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using several different methods I will put below but usually I come out with the wrong number or an error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data program.new;&lt;BR /&gt;set sheet.old;&lt;BR /&gt;keep testresults Remarks;&lt;BR /&gt;CB = indexc(tests, 'Hep', 'HBsAg');&lt;BR /&gt;CB2 = indexc(remarks, 'Hep', 'HBsAG');&lt;BR /&gt;IF CB = 0 then delete;&lt;BR /&gt;IF CB2 = 0 then delete;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;PRE&gt;data program.new;&lt;BR /&gt;set sheet.old;&lt;BR /&gt;if index(upcase(tests), 'HEP') then Hepcheck = "yes";&lt;BR /&gt;if index(upcase(tests), 'HBSAG') then HEpCheck = "yes";&lt;BR /&gt;if index(upcase(remarks), 'HEP') then Hepcheck = "yes";&lt;BR /&gt;if index(upcase(remarks), 'HBSAG') then HepCheck = "yes";&lt;BR /&gt;else Hepcheck = "no";&lt;BR /&gt;&lt;BR /&gt;if hepcheck = "no" then delete;&lt;BR /&gt;keep hepcheck;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;if someone could help that would be great!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 21:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755141#M238245</guid>
      <dc:creator>Cooksam13</dc:creator>
      <dc:date>2021-07-19T21:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: finding a text in various columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755143#M238247</link>
      <description>&lt;P&gt;In your second approach, please use else if , otherwise the last condition will ruin all your logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(upcase(tests), 'HEP') then Hepcheck = "yes";
else if index(upcase(tests), 'HBSAG') then HEpCheck = "yes";
else if index(upcase(remarks), 'HEP') then Hepcheck = "yes";
else if index(upcase(remarks), 'HBSAG') then HepCheck = "yes";
else Hepcheck = "no";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Jul 2021 21:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755143#M238247</guid>
      <dc:creator>Rydhm</dc:creator>
      <dc:date>2021-07-19T21:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: finding a text in various columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755144#M238248</link>
      <description>&lt;P&gt;What are the errors you're getting?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 21:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755144#M238248</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-19T21:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: finding a text in various columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755159#M238258</link>
      <description>&lt;P&gt;You don't want INDEXC.&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;P class="xis-shortDescription"&gt;Indexc Searches a character expression for any of the specified characters, and returns the position of that character.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;So in this example:&lt;/P&gt;
&lt;PRE&gt;data junk;
   input word $;
   pos = indexc(word,'hep');
datalines;
p
ah
ace
;
&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;you get Pos values of 1, because there is a p in the first position in the first value of word, 2 because h is the second letter in the second value and 3 because e is the third letter in word on the observation. ANY of the characters.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;If you want to find the entire string HEP then you need to use one of Index, Indexw, Find or Findw. And as in your other post the things like case consideration and presence as a substring in other words is critical.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;It is best to provide some example values of your variable and what you expect the result to look like.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;And for consistency sake on my part, I strongly suggest that you use 1/0 numeric coding instead of 'yes' 'no' text coding.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;Later when you want to do summaries you can get the number of yes by using the SUM , the percent yes with the Mean statistics in any of multiple procedures. Max =1 tells you if that at least one value is 1, Max=0 tells you none are 1, Range=0 tells you all are the same value. A bit trickier to get such things with 'yes' / 'no'.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Jul 2021 23:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755159#M238258</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-19T23:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: finding a text in various columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755161#M238260</link>
      <description>&lt;P&gt;Try prxmatch?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2021 23:30:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/755161#M238260</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-07-19T23:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: finding a text in various columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/757526#M239130</link>
      <description>&lt;P&gt;Thank you for that quick fix, I tried to condense the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data program.ds2054;&lt;BR /&gt;set sheet.ds2054;&lt;BR /&gt;if index(upcase(classbotherspecify), 'HEP C' or 'HEPATITIS C') then hepcheck = 0;&lt;BR /&gt;else if index(upcase(classbotherspecify), 'HEP' or 'HBSAG' or 'HBV') then Hepcheck = 1 ;&lt;BR /&gt;Else if index(upcase(remarks), 'HEP C' or 'HEPATITIS C') then hepcheck =0;&lt;BR /&gt;Else if index(upcase(remarks), 'HEP' or 'HBSAG' or 'HBV') then hepcheck =1;&lt;BR /&gt;else if index(upcase (OtherClassBDetails), 'HEP C' or 'HEPATITIS C') then hepcheck =0;&lt;BR /&gt;else if index(upcase (OtherClassBDetails), 'HEP' or 'HBSAG' or 'HBV') then hepcheck =1;&lt;BR /&gt;&lt;BR /&gt;else Hepcheck = 0;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;However I get this error now and no data shows up even though i had a lot of data the other way&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasNote"&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;71:38 71:49 72:43 72:52 72:63 73:32 73:43 74:32 74:41 74:52 75:44 75:55 76:44 76:53 76:64&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;80:39 80:53 81:32 81:46 82:42 82:56&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;71:46 72:60 73:40 74:49 75:23 75:52 76:23 76:61 80:50 81:43 82:22 82:53&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Variable OtherClassBDetails is uninitialized.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid numeric data, 'HEP C' , at line 71 column 38.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid numeric data, 'HEPATITIS C' , at line 71 column 49.&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Invalid numeric data, 'HEP' , at line 72 column 43.&lt;/DIV&gt;</description>
      <pubDate>Tue, 27 Jul 2021 20:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/finding-a-text-in-various-columns/m-p/757526#M239130</guid>
      <dc:creator>Cooksam13</dc:creator>
      <dc:date>2021-07-27T20:55:39Z</dc:date>
    </item>
  </channel>
</rss>

