<?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 Multicharacter string in Scan function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406435#M98967</link>
    <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to parse my string into 3 parts, and the delimiter is "//". Example of my string:&lt;/P&gt;&lt;P&gt;ItemA=Andy//Male//Cat. However, I have some strings that have "/" as part of the string, and I'm unable to parse them properly, e.g.:&lt;/P&gt;&lt;P&gt;Bac/h//Male//Dog&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used the following function but it doesnt parse properly. I've tried to replace Q with M but it doesnt work too.Appreciate any help pls. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name = scan(ItemA,1,"//",'Q');&lt;/P&gt;&lt;P&gt;gender =&lt;SPAN&gt;scan(ItemA,2,"//",'Q');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;animal =&lt;SPAN&gt;scan(ItemA,2,"//",'Q');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2017 08:52:40 GMT</pubDate>
    <dc:creator>catisgar</dc:creator>
    <dc:date>2017-10-23T08:52:40Z</dc:date>
    <item>
      <title>Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406435#M98967</link>
      <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to parse my string into 3 parts, and the delimiter is "//". Example of my string:&lt;/P&gt;&lt;P&gt;ItemA=Andy//Male//Cat. However, I have some strings that have "/" as part of the string, and I'm unable to parse them properly, e.g.:&lt;/P&gt;&lt;P&gt;Bac/h//Male//Dog&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used the following function but it doesnt parse properly. I've tried to replace Q with M but it doesnt work too.Appreciate any help pls. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;name = scan(ItemA,1,"//",'Q');&lt;/P&gt;&lt;P&gt;gender =&lt;SPAN&gt;scan(ItemA,2,"//",'Q');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;animal =&lt;SPAN&gt;scan(ItemA,2,"//",'Q');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 08:52:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406435#M98967</guid>
      <dc:creator>catisgar</dc:creator>
      <dc:date>2017-10-23T08:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406437#M98968</link>
      <description>&lt;P&gt;A very clever solution to this kind of problem (multi-byte delimiters) can be found here: &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Handling-multi-character-word-delimiters/td-p/174611" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Handling-multi-character-word-delimiters/td-p/174611&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this is the first result of a google search for "sas scan multi-character delimiters".&lt;/P&gt;
&lt;P&gt;See Maxim 6.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 09:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406437#M98968</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-23T09:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406453#M98971</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/94918"&gt;@catisgar&lt;/a&gt;:&lt;/P&gt;&lt;P&gt;If you know some character that certainly does not occur in your string, you can use that as a substitute delimiter, here is an example using a hexadecimal NULL character, which is often a good candidate for this kind of stuff, as it is used as an end-of-string marker in C:&lt;/P&gt;&lt;PRE&gt;data x;
  ItemA='Bac/h//Male//Dog';
  str=tranwrd(ItemA,'//','00'x);
  name = scan(str,1,'00'x);
  gender =scan(str,2,'00'x);
  animal =scan(str,3,'00'x);
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 10:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406453#M98971</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-10-23T10:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406538#M98994</link>
      <description>&lt;PRE&gt;
Here is another one.


data x;
  ItemA='Bac/h//Male//Dog';

temp=cats(ItemA,'//');
p=find(ItemA,'//');
if p=0 then do;want=ItemA; output;end;
 else do;
  do while(not missing(temp));
	p=find(temp,'//');
	want=substr(temp,1,p-1);
	output;
	temp=substr(temp,p+2);
  end;
 end;
run;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406538#M98994</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-23T14:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406544#M98997</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/94918"&gt;@catisgar&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im trying to parse my string into 3 parts, and the delimiter is "//". Example of my string:&lt;/P&gt;
&lt;P&gt;ItemA=Andy//Male//Cat. However, I have some strings that have "/" as part of the string, and I'm unable to parse them properly, e.g.:&lt;/P&gt;
&lt;P&gt;Bac/h//Male//Dog&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've used the following function but it doesnt parse properly. I've tried to replace Q with M but it doesnt work too.Appreciate any help pls. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;name = scan(ItemA,1,"//",'Q');&lt;/P&gt;
&lt;P&gt;gender =&lt;SPAN&gt;scan(ItemA,2,"//",'Q');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;animal =&lt;SPAN&gt;scan(ItemA,2,"//",'Q');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show an example of "doesn't work" and what the expected result should be.&lt;/P&gt;
&lt;P&gt;This seems to do what you request:&lt;/P&gt;
&lt;PRE&gt;data example;
   ItemA="Smith, John//Male//Dog";
   name = scan(ItemA,1,"//");
   gender =scan(ItemA,2,"//");
   animal =scan(ItemA,3,"//");
run;&lt;/PRE&gt;
&lt;P&gt;By the way, your example for animal requesting the second item as the same for the gender "wouldn't work".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406544#M98997</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-23T14:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406826#M99109</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;: // does not work as expected as a separator in scan(). Just run this slight modification of your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   ItemA="Smith/ John//Male//Dog";
   name = scan(ItemA,1,"//");
   gender =scan(ItemA,2,"//");
   animal =scan(ItemA,3,"//");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2017 07:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406826#M99109</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-24T07:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406951#M99146</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;: // does not work as expected as a separator in scan(). Just run this slight modification of your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   ItemA="Smith/ John//Male//Dog";
   name = scan(ItemA,1,"//");
   gender =scan(ItemA,2,"//");
   animal =scan(ItemA,3,"//");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;you're correct, I missed the OP&amp;nbsp; "sometimes" missing part of the delimeter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 14:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/406951#M99146</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-24T14:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multicharacter string in Scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/407081#M99168</link>
      <description>&lt;P&gt;SCAN() does not support using multiple character strings as a delimiter.&amp;nbsp; But the INFILE statement does.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  length name gender animal $20 ;
  infile cards dlmstr='//' truncover ;
  input name gender animal;
cards;
Andy//Male//Cat
Bac/h//Male//Dog
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if you already have the string in a dataset you could try using the "_infile_ trick" to let you use the INPUT&amp;nbsp;statement to read from&amp;nbsp;your character variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  length name gender animal $20 ;
  infile cards dlmstr='//' truncover ;
  input @@;
  _infile_=itema;
  input @1 name gender animal @@;
cards;
Ignore me
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 21:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multicharacter-string-in-Scan-function/m-p/407081#M99168</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-24T21:12:53Z</dc:date>
    </item>
  </channel>
</rss>

