<?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 Delimiter in scan function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885529#M349926</link>
    <description>&lt;P&gt;I need to split a character variable by multiple characters and the keyword "AND". When I am using the following it is considering&amp;nbsp; all the 3 letters separately as delimiters.&lt;/P&gt;&lt;P&gt;gen1=scan(GenericName, 1, '"AND",&amp;amp;/+');&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jul 2023 00:55:45 GMT</pubDate>
    <dc:creator>BayzidurRahman</dc:creator>
    <dc:date>2023-07-20T00:55:45Z</dc:date>
    <item>
      <title>Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885529#M349926</link>
      <description>&lt;P&gt;I need to split a character variable by multiple characters and the keyword "AND". When I am using the following it is considering&amp;nbsp; all the 3 letters separately as delimiters.&lt;/P&gt;&lt;P&gt;gen1=scan(GenericName, 1, '"AND",&amp;amp;/+');&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 00:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885529#M349926</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-20T00:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885534#M349928</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to split a character variable by multiple characters and the keyword "AND". When I am using the following it is considering&amp;nbsp; all the 3 letters separately as delimiters.&lt;/P&gt;
&lt;P&gt;gen1=scan(GenericName, 1, '"AND",&amp;amp;/+');&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is how the SCAN() function works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what is it you actually want to do?&lt;/P&gt;
&lt;P&gt;Please provide example input data.&amp;nbsp; Explain the rules.&amp;nbsp; Show what results you need.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 01:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885534#M349928</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-20T01:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885535#M349929</link>
      <description>&lt;P&gt;I have the data&lt;/P&gt;&lt;P&gt;Var&lt;/P&gt;&lt;P&gt;paracetamol AND nurophen + vitamin/mineral&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want&lt;/P&gt;&lt;P&gt;var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;vr3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;v4&lt;/P&gt;&lt;P&gt;paracetamol&amp;nbsp; &amp;nbsp;nurophen&amp;nbsp; &amp;nbsp;vitamin&amp;nbsp;&amp;nbsp;mineral&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 01:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885535#M349929</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-20T01:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885536#M349930</link>
      <description>&lt;P&gt;If you don't want "and" then you could replace occurences of " and " , lead and trailing spaces with a single delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way, which replaces the AND with a space:&lt;/P&gt;
&lt;PRE&gt;data example;
   string = "paracetamol AND nurophen + vitamin/mineral";
   newstring = tranwrd(string,' AND ',' ');
run;&lt;/PRE&gt;
&lt;P&gt;Caution: tranwrd is case sensitive so would not match 'and' or 'And' or other than all upper case. You might consider upper or lower case conversion of the whole string for consistency.&lt;/P&gt;
&lt;P&gt;You would also have to include a space in the Scan delimiter list.&lt;/P&gt;
&lt;P&gt;Quite often string manipulation means do one thing then another. Sometimes you can nest functions but may lose track of why you did such later.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 02:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885536#M349930</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-20T02:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885537#M349931</link>
      <description>&lt;P&gt;Thanks for the suggestions.&lt;BR /&gt;I do not want to replace AND by a space and then use space as a delimiter. Because some of my other target words will contain space and I want to keep them.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 02:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885537#M349931</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-20T02:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885538#M349932</link>
      <description>&lt;P&gt;So replace all of the AND's with &amp;amp; instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input var $80.;
cards;
paracetamol AND nurophen + vitamin/mineral
acetaminophen and ibuprofen And naproxen 
;

data want;
  dlm=',&amp;amp;/+';
  set have;
  fixed=var;
  do until(loc=0);
    loc=findw(fixed,'and',dlm,'si');
    if loc then fixed=catx('&amp;amp;',substrn(fixed,1,loc-1),substrn(fixed,loc+3));
  end;
  do index=1 to countw(fixed,dlm);
    newvar=left(scan(fixed,index,dlm));
    output;
  end;
  drop dlm loc fixed;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs                       var                        index    newvar

 1     paracetamol AND nurophen + vitamin/mineral      1      paracetamol
 2     paracetamol AND nurophen + vitamin/mineral      2      nurophen
 3     paracetamol AND nurophen + vitamin/mineral      3      vitamin
 4     paracetamol AND nurophen + vitamin/mineral      4      mineral
 5     acetaminophen and ibuprofen And naproxen        1      acetaminophen
 6     acetaminophen and ibuprofen And naproxen        2      ibuprofen
 7     acetaminophen and ibuprofen And naproxen        3      naproxen

&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jul 2023 02:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885538#M349932</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-20T02:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885543#M349937</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the suggestions.&lt;BR /&gt;I do not want to replace AND by a space and then use space as a delimiter. Because some of my other target words will contain space and I want to keep them.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;so use a different character.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 02:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885543#M349937</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-20T02:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Delimiter in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885544#M349938</link>
      <description>&lt;P&gt;Thanks to both of you.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 02:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delimiter-in-scan-function/m-p/885544#M349938</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-07-20T02:46:28Z</dc:date>
    </item>
  </channel>
</rss>

