<?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 Extracting word(s) before comma delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643645#M192131</link>
    <description>&lt;P&gt;I need to extract words before a delimiter (comma) and can't figure out how to do it. In some cases it's one word and in other cases it's more than one word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Clay County, AL&lt;/P&gt;
&lt;P&gt;Clark County, AL&lt;/P&gt;
&lt;P&gt;La Paz County, AZ&lt;/P&gt;
&lt;P&gt;Santa Cruz County, AZ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for each of those, I want to extract all of the words before the comma. Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 28 Apr 2020 15:19:23 GMT</pubDate>
    <dc:creator>wernie</dc:creator>
    <dc:date>2020-04-28T15:19:23Z</dc:date>
    <item>
      <title>Extracting word(s) before comma delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643645#M192131</link>
      <description>&lt;P&gt;I need to extract words before a delimiter (comma) and can't figure out how to do it. In some cases it's one word and in other cases it's more than one word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Clay County, AL&lt;/P&gt;
&lt;P&gt;Clark County, AL&lt;/P&gt;
&lt;P&gt;La Paz County, AZ&lt;/P&gt;
&lt;P&gt;Santa Cruz County, AZ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for each of those, I want to extract all of the words before the comma. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 15:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643645#M192131</guid>
      <dc:creator>wernie</dc:creator>
      <dc:date>2020-04-28T15:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting word(s) before comma delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643647#M192132</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input words $30.;
cards;
Clay County, AL
Clark County, AL
La Paz County, AZ
Santa Cruz County, AZ
;

data want;
 set have;
 want=scan(words,1,',');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Apr 2020 15:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643647#M192132</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-28T15:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting word(s) before comma delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643650#M192133</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data example;
   set have;
   city = scan(variable,1,',');
   state= scan(variable,2,',');
run;&lt;/PRE&gt;
&lt;P&gt;SCAN function will extract "words" from a variable, with the number 1,2, 3 etc indicating which "word" and the last parameter is delimiter character(s). By default the function would use space and a few other characters but you can limit to a single delimiter character by specifying in the third position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You did not mention the name of your existing variable so...&lt;/P&gt;
&lt;P&gt;If you know how long you want the resulting variable to be then best is to provide a LENGTH statement before extracting. Otherwise the variables are likely to inherit the length of the source variable which may lead to wasted disk space use.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 15:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643650#M192133</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-28T15:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting word(s) before comma delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643742#M192168</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input text$30.;
datalines;
Clay County, AL
Clark County, AL
La Paz County, AZ
Santa Cruz County, AZ
;
run;

data want (drop= text);
set have;
City = scan(text, 1, ',');
State = scan(text, 2, ',');
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Apr 2020 23:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-word-s-before-comma-delimiter/m-p/643742#M192168</guid>
      <dc:creator>sdhilip</dc:creator>
      <dc:date>2020-04-28T23:39:18Z</dc:date>
    </item>
  </channel>
</rss>

