<?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: Using the FIND() statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632770#M187620</link>
    <description>I don't think -1 needs to be in quotes? &lt;BR /&gt;What happens if you use the function without the quotes around it?</description>
    <pubDate>Tue, 17 Mar 2020 19:52:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-03-17T19:52:40Z</dc:date>
    <item>
      <title>Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632769#M187619</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am running into a big of a snag, I am using the following code to create a new variable for data mapping purposes:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data txttest1;&lt;BR /&gt;set work.ptxt;&lt;BR /&gt;if find(tx, 'mg', "i")&amp;gt;0 then P2_PR_Dose_Units=01;&lt;BR /&gt;else if find(tx, 'g', "i", "-1")=1 and find(tx, 'mg', "i")=0 then P2_PR_Dose_Units=02;&lt;BR /&gt;else if find(tx, 'unit', "i")&amp;gt;0 then P2_PR_Dose_Units=03;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, my 1s and 3s are coming up okay, but all 2s are coming up as missing variables. Basically, I am trying to count from right to left and if the first letter is a g but does not contain mg then it should be a 2, if there is a g after the first position from right to left then it needs to be either a 1 o a 3 depending on the category. I am mainly having issues getting the start position to work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 19:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632769#M187619</guid>
      <dc:creator>GScottEpi</dc:creator>
      <dc:date>2020-03-17T19:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632770#M187620</link>
      <description>I don't think -1 needs to be in quotes? &lt;BR /&gt;What happens if you use the function without the quotes around it?</description>
      <pubDate>Tue, 17 Mar 2020 19:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632770#M187620</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-17T19:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632771#M187621</link>
      <description>&lt;P&gt;It runs without errors, but I still get missing values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, one of my response categories could be Tylenol 1g, I would want this to show up in the new variable with a value of 2. This is opposed to guanfacin 5mg, which I would want to show up as a 1 in the new variable.&amp;nbsp; I was thinking that since I am counting from right to left this would work, but it is not.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 19:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632771#M187621</guid>
      <dc:creator>GScottEpi</dc:creator>
      <dc:date>2020-03-17T19:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632772#M187622</link>
      <description>&lt;P&gt;This doesn't make any sense.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; find(tx, 'g', "i", "-1")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is the "-1" supposed to mean?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your description makes it sound like you want to test if the last character is a G.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;indexc(char(tx,length(tx)),'gG')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Mar 2020 19:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632772#M187622</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-17T19:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632773#M187623</link>
      <description>&lt;P&gt;With the -1 I am trying to set a starting position so that it is being read right to left.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And sort of, the data I have lists grams for each medication with a g at the end, but those measured in mg needs to be differentiated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632773#M187623</guid>
      <dc:creator>GScottEpi</dc:creator>
      <dc:date>2020-03-17T20:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632774#M187624</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/317097"&gt;@GScottEpi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;With the -1 I am trying to set a starting position so that it is being read right to left.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And sort of, the data I have lists grams for each medication with a g at the end, but those measured in mg needs to be differentiated.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In that case you need to give FIND() a NUMBER, not a string.&amp;nbsp; And also test if the result is the last position in the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; find(tx, 'g', "i", -1)=length(tx)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:02:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632774#M187624</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-17T20:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632775#M187625</link>
      <description>&lt;P&gt;Sorry, I don't fully understand your response, when you say give it a number instead of a string? And what does "length" mean in the part that says =length(tx)?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632775#M187625</guid>
      <dc:creator>GScottEpi</dc:creator>
      <dc:date>2020-03-17T20:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632778#M187626</link>
      <description>&lt;P&gt;I strongly suggest you start reading the documentation, because right now you seem to be quite clueless.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p00ab6ey29t2i8n1ihel88tqtga9.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FIND Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n0f6jve4kdxnh1n1m7c82fhosgih.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;LENGTH Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And consult the documentation whenever something is not completely clear to you (read: always; every good SAS coder does it). There is a VERY BIG reason why Maxim 1 is number one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&lt;/P&gt;
&lt;PRE&gt;"-1"&lt;/PRE&gt;
&lt;P&gt;is a string,&lt;/P&gt;
&lt;PRE&gt;-1&lt;/PRE&gt;
&lt;P&gt;is a number.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632778#M187626</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-17T20:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632780#M187627</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/317097"&gt;@GScottEpi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry, I don't fully understand your response, when you say give it a number instead of a string? And what does "length" mean in the part that says =length(tx)?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The documentation is clear that start position is a number.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xisDoc-argument"&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;start-position&lt;/EM&gt;&lt;/H4&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;is a numeric constant, variable, or expression with an integer value that specifies the position at which the search should start and the direction of the search.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;It is also clear that what it returns is to position that it was found.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;&lt;SPAN&gt;The FIND function searches&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;string&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;for the first occurrence of the specified&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;substring&lt;/EM&gt;&lt;SPAN&gt;, and returns the position of that substring. If the substring is not found in&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;string&lt;/EM&gt;&lt;SPAN&gt;, FIND returns a value of 0.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;By testing for a result of 1 when searching from the back you are testing if the ONLY place there is G is the first position.&lt;/P&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:17:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632780#M187627</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-17T20:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632782#M187628</link>
      <description>&lt;P&gt;Okay, that makes more sense. Thank you so much for your responses.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632782#M187628</guid>
      <dc:creator>GScottEpi</dc:creator>
      <dc:date>2020-03-17T20:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632784#M187629</link>
      <description>Will your strings always end in units? Are you set on using find?&lt;BR /&gt;&lt;BR /&gt;If the units are always at the end, I'd consider using REVERSE() and checking the last two characters of the string. &lt;BR /&gt;&lt;BR /&gt;if substr(reverse(tx), 1, 2) = 'gm' then units=1;&lt;BR /&gt;else if substr(reverse(tx),1, 1) = 'g' then units=2;&lt;BR /&gt;&lt;BR /&gt;Note that having a leading zero in your units doesn't matter. Numbers don't store leading zeroes.</description>
      <pubDate>Tue, 17 Mar 2020 20:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632784#M187629</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-17T20:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using the FIND() statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632792#M187634</link>
      <description>&lt;P&gt;Note that you need to worry about the trailing spaces SAS adds to pad strings to the storage length.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if lowcase(reverse(trim(tx))) =: 'gm' then units=1;
else if lowcase(reverse(trim(tx))) =: 'g' then units=2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Mar 2020 20:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-the-FIND-statement/m-p/632792#M187634</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-17T20:52:13Z</dc:date>
    </item>
  </channel>
</rss>

