<?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: New User-Trouble with Extracting in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900192#M40110</link>
    <description>&lt;P&gt;Find the location of the word COUNTY. On your first row, that word begins at position 9. So then take the text in positions 1 through 8 (and optionally trim the blank off the end)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;position=find(regional,'county','i');
county_name=substr(regional,1,position-1);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 26 Oct 2023 18:56:56 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-10-26T18:56:56Z</dc:date>
    <item>
      <title>New User-Trouble with Extracting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900189#M40108</link>
      <description>&lt;P&gt;Hi SAS coders!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract the county from a string variable that is meshed in with the estimate and CI.&lt;/P&gt;&lt;P&gt;So the variable (called Regional) looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;LARIMER County/Regional Estimate 14% (95% C.I.: 11.9 - 16.2)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;LAS ANIMASCounty/Regional Estimate 16.7% (95% C.I.: 9.6 - 23.8)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract the LARIMER and LAS ANIMAS into their own variable and call it "COUNTY"&lt;/P&gt;&lt;P&gt;I've used SCAN, SUBSTR, COMPRESS, all the extracting functions and they always come out not ideal. My end result should be&lt;/P&gt;&lt;P&gt;LARIMER&lt;/P&gt;&lt;P&gt;LAS ANIMAS&lt;/P&gt;&lt;P&gt;The code I was using is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;DATA WANT;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SET OLD;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;COUNTY = COMPRESS(SCAN(Regional, 1,'C'),'');&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;P&gt;The end result of this code is&amp;nbsp;&lt;/P&gt;&lt;P&gt;LARIMER&lt;/P&gt;&lt;P&gt;LASANIMAS&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to produce the output where LASANIMAS has a space so it should look like LAS ANIMAS.&lt;/P&gt;&lt;P&gt;Also some of the county names that I am working with start with C like "Cheyenne" and because I put the delimiter as "C" the county name cuts off so it produces an output of "heyenne"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know what I am doing wrong.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900189#M40108</guid>
      <dc:creator>kcvaldez98</dc:creator>
      <dc:date>2023-10-26T18:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: New User-Trouble with Extracting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900192#M40110</link>
      <description>&lt;P&gt;Find the location of the word COUNTY. On your first row, that word begins at position 9. So then take the text in positions 1 through 8 (and optionally trim the blank off the end)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;position=find(regional,'county','i');
county_name=substr(regional,1,position-1);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900192#M40110</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-26T18:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: New User-Trouble with Extracting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900246#M40120</link>
      <description>&lt;P&gt;Don't forget to set a length for your county name long enough to hold the longest expected value.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 22:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900246#M40120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-26T22:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: New User-Trouble with Extracting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900254#M40121</link>
      <description>&lt;P&gt;It appears that REGIONAL has the county name, followed by the string "County", followed by a forward slash, and then other information irrelevant to extracting the county name.&amp;nbsp; And the string "County" may or may not be preceded by a blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;P&gt;(1) extract the text prior to the "/":&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;= scan(regional,1,'/')&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(2) then eliminate the last 6 non-blank characters:&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;=substr(of above,1,length(of above)-6)&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length county $25;
  county=substr(scan(regional,1,'/')
               ,1
               ,length(scan(regional,1,'/'))-6
               );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if the word "County" was always spelled in lowercase except the first letter, you could avoid using the substr function in (2).&amp;nbsp; Instead, you could apply a somewhat simpler expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length county $25;
  county=tranwrd(scan(regional,1,'/'),'County','');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This, of course, assumes that the string 'County' does not occur twice (once before the slash, and once as part of the county's proper name) in the REGION variable.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 00:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900254#M40121</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-10-27T00:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: New User-Trouble with Extracting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900256#M40122</link>
      <description>&lt;P&gt;If you wanted the keep the spaces why did you remove them?&amp;nbsp; Remove the COMPRESS() function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure none of the county names have an uppercase letter C?&amp;nbsp; If they do your SCAN() function call is also not what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 01:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900256#M40122</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-27T01:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: New User-Trouble with Extracting</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900258#M40123</link>
      <description>&lt;P&gt;And below yet another option using a regular expression.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input have_str $100.;
  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)
xxx xxx/Regional Estimate 16.7% (95% C.I.: 9.6 - 23.8)
;

data want(drop=_:);
  set have;
  length county $40.;
  _prxid = prxparse('/^.*(?=county\/)/oi');
  call prxsubstr(_prxid, have_str, _pos, _len);
  if _len&amp;gt;0 then county = substr(have_str, _pos, _len);
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-1698370407970.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/89128iCA740E72E87D1D3F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1698370407970.png" alt="Patrick_0-1698370407970.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 01:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-User-Trouble-with-Extracting/m-p/900258#M40123</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-27T01:39:36Z</dc:date>
    </item>
  </channel>
</rss>

