<?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: Extract a String Help in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901073#M40161</link>
    <description>&lt;P&gt;Thank you, that makes a lot more sense. Also to add, how do I format it without the % at the end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2023 14:15:55 GMT</pubDate>
    <dc:creator>kcvaldez98</dc:creator>
    <dc:date>2023-11-01T14:15:55Z</dc:date>
    <item>
      <title>Extract a String Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/900970#M40155</link>
      <description>&lt;P&gt;Hi SAS coders,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on this dataset where I am trying to extract the county estimates from a variable string. I've tried using all the extraction functions (SCAN, SUBSTR, etc.) and when I do extract the estimate, it always shows some counties including "Esti" instead of the percentage.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2023-10-27 at 10.08.26 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89288iB4C5F529AA539DC7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screen Shot 2023-10-27 at 10.08.26 PM.png" alt="Screen Shot 2023-10-27 at 10.08.26 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a screenshot to show what I mean. I want to be able to extract all the estimates without this error. I know it's because there are extra spaces between the county names, but I don't know how to extract without the spaces ruining the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a dataset that has county names and estimates and with the counties with the extra space.&lt;/P&gt;&lt;P&gt;*This string is named Regional*&lt;/P&gt;&lt;P&gt;LARIMER County/Regional Estimate 14% (95% C.I.: 11.9 - 16.2)&lt;BR /&gt;LAS ANIMASCounty/Regional Estimate 16.7% (95% C.I.: 9.6 - 23.8)&lt;BR /&gt;FREMONT County/Regional Estimate 15.5% (95% C.I.: 10.3 - 20.7)&lt;BR /&gt;CONEJOS County/Regional Estimate 9.9% (95% C.I.: 2.6 - 17.1)&lt;BR /&gt;EAGLE County/Regional Estimate 14.5% (95% C.I.: 9.9 - 19.1)&lt;BR /&gt;LA PLATA County/Regional Estimate 25.1% (95% C.I.: 19.7 - 30.5)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;The code I have used to show that specific output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; SET Have;&lt;/P&gt;&lt;P&gt;LENGTH &amp;nbsp; &amp;nbsp; CountyEstimate $4.;&lt;BR /&gt;CountyEstimate&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;=COMPRESS(SCAN(Regional,5, 'e &amp;nbsp;%'));&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advise.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 21:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/900970#M40155</guid>
      <dc:creator>kcvaldez98</dc:creator>
      <dc:date>2023-10-31T21:06:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a String Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/900972#M40156</link>
      <description>&lt;P&gt;A two step process:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p16rdsa30vmm43n1ej4936nwa01t.htm#n1lwsp8kjbhdnyn12esn4kh14621" target="_self"&gt;FINDW()&lt;/A&gt; function to find the location of the word Estimate.&lt;/LI&gt;
&lt;LI&gt;Use the SCAN and SUBSTR function to find first "word" after the location found above plus 9 characters. This assumes there is always a space after the word Estimate.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    string='LA PLATA County/Regional Estimate 25.1% (95% C.I.: 19.7 - 30.5)';
run;

data want;
    set have;
    where=findw(string,'Estimate',' ');
    estimate=scan(substr(string,where+9),1,' %');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Feel free to combine the two steps into one, if you would like. Feel free to turn the answer into a numeric variable, if you want.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 21:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/900972#M40156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-31T21:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a String Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/900975#M40158</link>
      <description>&lt;P&gt;Your code is always extracting the 5th word which of course can't work if county names can consist of one or several words.&lt;/P&gt;
&lt;P&gt;This has already been dealt with in proposed answer in your last question &lt;A href="https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900189#M40108" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;and variations of the answers provided should also work for the case at hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you would deal with a string where the sub-strings you're after are always on the same position (like always the second word) then your current code would work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the scan() function with counting words from end to start then you're actually dealing with such a consistent structure. For your current case the following should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input regional $200.;
  datalines;
LARIMER County/Regional Estimate 14% (95% C.I.: 11.9 - 16.2)
LAS ANIMASCounty/Regional Estimate 16.7% (95% C.I.: 9.6 - 23.8)
FREMONT County/Regional Estimate 15.5% (95% C.I.: 10.3 - 20.7)
CONEJOS County/Regional Estimate 9.9% (95% C.I.: 2.6 - 17.1)
EAGLE County/Regional Estimate 14.5% (95% C.I.: 9.9 - 19.1)
LA PLATA County/Regional Estimate 25.1% (95% C.I.: 19.7 - 30.5)
;

data want;
  set have;
  length CountyEstimate 8.;
  format CountyEstimate percent8.1;
  CountyEstimate = input(scan(strip(regional),-6,' '),percent.);
run;

proc print data=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Oct 2023 22:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/900975#M40158</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-31T22:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a String Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901073#M40161</link>
      <description>&lt;P&gt;Thank you, that makes a lot more sense. Also to add, how do I format it without the % at the end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 14:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901073#M40161</guid>
      <dc:creator>kcvaldez98</dc:creator>
      <dc:date>2023-11-01T14:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a String Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901077#M40164</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/456544"&gt;@kcvaldez98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, that makes a lot more sense. Also to add, how do I format it without the % at the end?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Remove or change the FORMAT statement.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 14:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901077#M40164</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-01T14:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a String Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901171#M40171</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/456544"&gt;@kcvaldez98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you, that makes a lot more sense. Also to add, how do I format it without the % at the end?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Below some options. Variable option_2 is the same than in the previous answer just without the percent format applied.&lt;/P&gt;
&lt;P&gt;Given your source values are in percent I consider option_2 as "correct" - but that's of course just how I see things.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length option_1 $6;
  option_1 = scan(strip(regional),-6,' %');

  /*format option_2 percent8.1;*/
  option_2 = input(scan(strip(regional),-6,' '),percent.);

  option_3 = option_2*100;

  option_4 = input(scan(strip(regional),-6,' %'),best32.);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1698878850034.png" style="width: 627px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89321i5B1CAE4723358D71/image-dimensions/627x163?v=v2" width="627" height="163" role="button" title="Patrick_0-1698878850034.png" alt="Patrick_0-1698878850034.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2023 22:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-a-String-Help/m-p/901171#M40171</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-01T22:49:12Z</dc:date>
    </item>
  </channel>
</rss>

