<?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: Strange behavior when splitting a column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374718#M276367</link>
    <description>&lt;P&gt;Note that if you're reading this data from a text file you can use the DLMSTR option on the infile statement to specify a delimiter that's a specific string.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jul 2017 21:18:04 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-07-10T21:18:04Z</dc:date>
    <item>
      <title>Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374668#M276361</link>
      <description>&lt;P&gt;This should have been a stright forward case.&lt;/P&gt;
&lt;P&gt;I am trying to split the contents of a column into multiple columns based on the pccurance of the string '_x000D_'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
&amp;nbsp; set t;
&amp;nbsp; length reason1-reason11 $10;
&amp;nbsp; array reason(11) $;
&amp;nbsp; do _i = 1 to dim(reason);
&amp;nbsp; &amp;nbsp; reason[_i] = scan(lowcase(TextBox),_i,"_x000D_");
&amp;nbsp; end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The string to split looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IDN: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0742520_x000D_Surname: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; JOHN_x000D_Given Names: &amp;nbsp; Wayen Joe_x000D_Gender: Male_x000D_DOB: 01/10/1911_x000D_DOB: _x000D__x000D_&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the result of the code is erratic and it looks like SAS is not splitting by&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_x000D_&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes it is splitting by "D", others by space etc, please see attached screenshot of splitting the string above&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;am i missing something here??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/14061i91F6CF7D6FB43DD4/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Screen Shot 2017-07-10 at 9.20.10 pm.png" title="Screen Shot 2017-07-10 at 9.20.10 pm.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/14062i0B232EBF05A1E4DE/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Screen Shot 2017-07-10 at 9.21.47 pm.png" title="Screen Shot 2017-07-10 at 9.21.47 pm.png" /&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374668#M276361</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2017-07-10T19:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374671#M276362</link>
      <description>&lt;P&gt;A couple of things ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The third parameter of SCAN is&amp;nbsp;a list of characters, not a word.&amp;nbsp; So any instance of any of those characters is considered a delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, your new variables are being defined as 10 characters long.&amp;nbsp; You might want to switch to a longer length, to hold some of the longer values that your original string contains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at the INDEX function instead of SCAN.&amp;nbsp; That will find the location of your key word, and then SUBSTR can pick out the characters before the key word.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374671#M276362</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-10T19:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374677#M276363</link>
      <description>&lt;P&gt;Because your delimiter is a string you may want to use PRXPARSE instead of FIND/INDEXW.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374677#M276363</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-10T19:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374682#M276364</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;is right in his remarks, but even if the 3rd argument of scan was a string (which is not),&lt;/P&gt;
&lt;P&gt;then after using function &lt;STRONG&gt;lowcase&lt;/STRONG&gt; thd&lt;STRONG&gt; D&lt;/STRONG&gt; will change into &lt;STRONG&gt;d&amp;nbsp;&lt;/STRONG&gt;and you will not find the string _x000&lt;STRONG&gt;D&lt;/STRONG&gt;_&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374682#M276364</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-10T19:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374691#M276365</link>
      <description>&lt;P&gt;Perhaps this will give you a different starting place:&lt;/P&gt;
&lt;PRE&gt;data junk;
string ="IDN:         0742520_x000D_Surname:         JOHN_x000D_Given Names:   Wayen Joe_x000D_Gender: Male_x000D_DOB: 01/10/1911_x000D_DOB: _x000D__x000D_";
newstr = tranwrd(string,'_x000D_',' ');
  length reason1-reason11 $20;
  array reason(11) $;
  do _i = 1 to dim(reason);
    reason[_i] = scan(newstr,_i);
  end;

run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jul 2017 20:06:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374691#M276365</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-10T20:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374716#M276366</link>
      <description>&lt;P&gt;If you want to use SCAN() then first use TRANWRD() to convert your string into a single character. &amp;nbsp;You could just pick any character that is not already in your string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  textbox=
  'IDN:         0742520_x000D_Surname:         JOHN_x000D_Given'
||' Names:   Wayen Joe_x000D_Gender: Male_x000D_DOB: 01/10/1911'
||'_x000D_DOB: _x000D__x000D_'
  ;
run;

data want;
  set have ;
  array reason(11) $50 ;
  do i = 1 to dim(reason);
    reason[i] = scan(tranwrd(TextBox,'_x000D_','|'),i,'|');
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;1336  data _null_;
1337    set want ;
1338    put (_all_) (=:$quote./);
1339  run;

textbox="IDN:         0742520_x000D_Surname:         JOHN_x000D_Given Names:   Wayen Joe_x000D_Gender:
 Male_x000D_DOB: 01/10/1911_x000D_DOB: _x000D__x000D_"
reason1="IDN:         0742520"
reason2="Surname:         JOHN"
reason3="Given Names:   Wayen Joe"
reason4="Gender: Male"
reason5="DOB: 01/10/1911"
reason6="DOB:"
reason7=""
reason8=""
reason9=""
reason10=""
reason11=""
NOTE: There were 1 observations read from the data set WORK.WANT.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 21:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374716#M276366</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-10T21:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374718#M276367</link>
      <description>&lt;P&gt;Note that if you're reading this data from a text file you can use the DLMSTR option on the infile statement to specify a delimiter that's a specific string.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 21:18:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374718#M276367</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-10T21:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Strange behavior when splitting a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374719#M276368</link>
      <description>&lt;P&gt;Here is a way that you could use the DLMSTR= option on the INFILE statement. This is called the "_INFILE_ Trick".&lt;/P&gt;
&lt;P&gt;Create a dummy file with at least one line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename dummy temp ;
data _null_ ; 
  file dummy;
  put; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then create&amp;nbsp;a data step that purports to read from that file, but that really takes the values of TextBox and assigns them to the _INFILE_ automatic&amp;nbsp;variable so that you can use an INPUT statement to parse the string. &amp;nbsp;The&amp;nbsp;@1 and&amp;nbsp;@@ in the INPUT statements are critical to prevent it from reading past the end of the dummy text file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2 ;
  infile dummy lrecl=32767 truncover dlmstr='_x000D_';
  input @@;
  set have ;
  _infile_=textbox;
  input @1 (reason1-reason10) (:$50.) @@;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Jul 2017 21:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Strange-behavior-when-splitting-a-column/m-p/374719#M276368</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-10T21:21:26Z</dc:date>
    </item>
  </channel>
</rss>

