<?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 SUBSTR AND FIND FUNCTION TOGETHER in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403393#M278927</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length var $100.;
var="Charity 90%. Save the Whales 10%";output;
var="Relief Assist. Inc. 20%. Cuida Ltd. 80%";output;
run;

data want;
set have;

index_value = find(var, '%');
value = substr(var, index_Value-3,3 );
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Oct 2017 23:35:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-10-11T23:35:40Z</dc:date>
    <item>
      <title>USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403390#M278925</link>
      <description>&lt;DIV class="page"&gt;&lt;DIV class="page"&gt;&lt;DIV class="page"&gt;&amp;nbsp;I am new at Enterprise Guide and need some help.&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;I am specifically supposed to use the FIND function and the SUBSTR to pull out only the first percentage in a character string. &amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;It looks like this:&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;The column is Recipients&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;Then in the column it lists:&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;Charity 90%. Save the Whales 10%&lt;/DIV&gt;&lt;DIV class="page"&gt;Relief Assist. Inc. 20%. Cuida Ltd. 80%&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;and so on. There are a couple of hundred rows.&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;I need a column that shows only the first %.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;So, I created a computed column and did FIND(Recipients, "%",1)&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;Then I created a SUBSTR.&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;SUBSTR(Recipients,(&lt;SPAN&gt;FIND(Recipients, "%",1)),-3)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&lt;SPAN&gt;This did not work. &amp;nbsp;I thought it would go to the position of the first % sign and then read the two numbers in&amp;nbsp;front of the % sign. &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&lt;SPAN&gt;Can someone help me with the correct FIND and SUBSTR combination?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&lt;SPAN&gt;This is one of the first SUBSTR&amp;nbsp;functions I have done and is the first time I had to use FIND. &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&lt;SPAN&gt;It should have shown 90% in the first row and 20% in the second row based on the example rows above.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 11 Oct 2017 23:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403390#M278925</guid>
      <dc:creator>Gianna41</dc:creator>
      <dc:date>2017-10-11T23:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403392#M278926</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/171107"&gt;@Gianna41&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;DIV class="page"&gt;
&lt;DIV class="page"&gt;
&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="page"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="page"&gt;&lt;SPAN&gt;This did not work. &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How did this not work?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 23:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403392#M278926</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-11T23:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403393#M278927</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length var $100.;
var="Charity 90%. Save the Whales 10%";output;
var="Relief Assist. Inc. 20%. Cuida Ltd. 80%";output;
run;

data want;
set have;

index_value = find(var, '%');
value = substr(var, index_Value-3,3 );
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 23:35:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403393#M278927</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-11T23:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403394#M278928</link>
      <description>&lt;P&gt;You don't use the substr function correctly. Look up the documentation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
 STR = 'Charity 90%. Save the Whales 10%';
 VAL = substr(STR,(find(STR, "%",1))-2,2);
 put VAL=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;VAL=90&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 23:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403394#M278928</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-10-11T23:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403396#M278929</link>
      <description>&lt;P&gt;I would do something along these lines.&amp;nbsp; You typically have to use find results conditionally.&amp;nbsp; What if there is not a percent?&amp;nbsp; You need to support percentages of varying lengths.&amp;nbsp; I don't know what all of you values look like.&amp;nbsp; This code assumes blanks (or beginning of line) in front of each percentage.&amp;nbsp; If that is not the case, you need to adjust your code accordingly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
 input str $ 1-40;
 i = find(str, '%');
 if i gt 1 then val = scan(substr(str, 1, i - 1), -1, ' ');
 cards;
Charity 90%. Save the Whales 10%
Charity 90000%. Save the Whales 10%
Charity 9%. Save the Whales 10%
12%
Nothing here to see
;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 00:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403396#M278929</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-10-12T00:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403416#M278930</link>
      <description>&lt;P&gt;If you're sure there will always be a % sign, you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;value = scan(scan(string, 1, '%'), -1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 01:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/403416#M278930</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-12T01:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: USING SUBSTR AND FIND FUNCTION TOGETHER</title>
      <link>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/535517#M278931</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;It could be the easiest solution i believe ( Tried and tested) . Please let me know if it helps. Thanks!!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input str $ 1-40;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;y=index(str,'%');&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;val = substr(str,y-2);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Charity 90%&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Save the Whales 10%&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Relief Assist. Inc. 20%&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Cuida Ltd. 80%&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;proc print; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 346px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/27139iF8FEE076CF58B6F8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 08:43:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/USING-SUBSTR-AND-FIND-FUNCTION-TOGETHER/m-p/535517#M278931</guid>
      <dc:creator>subhani4</dc:creator>
      <dc:date>2019-02-14T08:43:42Z</dc:date>
    </item>
  </channel>
</rss>

