<?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 extract substrings from a string variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631564#M187141</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract multiple substrings from a string.&lt;/P&gt;&lt;P&gt;For example, I have a variable called Itinerary =&amp;nbsp;&amp;nbsp;Orlando, United States (North America) Start Date: 03/30/2020 - End Date: 04/01/2020|Fort Pierce, United States (North America) Start Date: 04/01/2020 - End Date: 04/07/2020|Fort Lauderdale, United States (North America) Start Date: 04/07/2020 - End Date: 04/07/2020&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to pull the substrings which are before and after the special character comma (,) So I would like to have a variable " location" which has Orlando, Unitedstates&lt;/P&gt;&lt;P&gt;Fort Pierce, United States&lt;/P&gt;&lt;P&gt;Fort Lauderdale, United States.&lt;/P&gt;&lt;P&gt;I have tried using Scan function but am able to pull just Orlando, United states but no the rest of the locations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Mar 2020 14:15:34 GMT</pubDate>
    <dc:creator>DivyaGadde</dc:creator>
    <dc:date>2020-03-12T14:15:34Z</dc:date>
    <item>
      <title>extract substrings from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631564#M187141</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to extract multiple substrings from a string.&lt;/P&gt;&lt;P&gt;For example, I have a variable called Itinerary =&amp;nbsp;&amp;nbsp;Orlando, United States (North America) Start Date: 03/30/2020 - End Date: 04/01/2020|Fort Pierce, United States (North America) Start Date: 04/01/2020 - End Date: 04/07/2020|Fort Lauderdale, United States (North America) Start Date: 04/07/2020 - End Date: 04/07/2020&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to pull the substrings which are before and after the special character comma (,) So I would like to have a variable " location" which has Orlando, Unitedstates&lt;/P&gt;&lt;P&gt;Fort Pierce, United States&lt;/P&gt;&lt;P&gt;Fort Lauderdale, United States.&lt;/P&gt;&lt;P&gt;I have tried using Scan function but am able to pull just Orlando, United states but no the rest of the locations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 14:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631564#M187141</guid>
      <dc:creator>DivyaGadde</dc:creator>
      <dc:date>2020-03-12T14:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: extract substrings from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631572#M187144</link>
      <description>&lt;P&gt;Is this whole data in one observation, or did you just put in the pipe characters to show ends of records?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's one observation, see here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input itinerary $500.;
datalines;
Orlando, United States (North America) Start Date: 03/30/2020 - End Date: 04/01/2020|Fort Pierce, United States (North America) Start Date: 04/01/2020 - End Date: 04/07/2020|Fort Lauderdale, United States (North America) Start Date: 04/07/2020 - End Date: 04/07/2020 
;

data want (keep=location);
set have;
length location $100;
do i = 1 to countw(itinerary,'|');
  location = scan(scan(itinerary,i,'|'),1,'(');
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 14:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631572#M187144</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-12T14:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: extract substrings from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631578#M187146</link>
      <description>&lt;P&gt;Is the location component following the comma (e.g. "United States") always followed by an open parenthesis?&amp;nbsp; If so, and if the location component preceding the comma ("Orlando") is always at the beginning of the string, then the open paren is, operationally speaking, the real special character, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; location=scan(strng,1,'(');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This just retrieve the first "word" in the string, where each word is all the text between (or preceding or following) the separator - in this case the "(" character.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Mar 2020 14:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-substrings-from-a-string-variable/m-p/631578#M187146</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-03-12T14:32:06Z</dc:date>
    </item>
  </channel>
</rss>

