<?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: parsing characters with multiple delimters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/462018#M117545</link>
    <description>Perfect really thank you!</description>
    <pubDate>Mon, 14 May 2018 12:35:15 GMT</pubDate>
    <dc:creator>jkim197</dc:creator>
    <dc:date>2018-05-14T12:35:15Z</dc:date>
    <item>
      <title>parsing characters with multiple delimters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/461936#M117533</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Hello SAS users&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I want to split a character variable into multiple (maximum 25) character variables based on comma ,&amp;nbsp; hyphen -&amp;nbsp; &amp;nbsp;slash /&amp;nbsp; &amp;nbsp;colon : semicolon&amp;nbsp;;&amp;nbsp; and space&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;var_name&lt;/TD&gt;&lt;TD&gt;var1&lt;/TD&gt;&lt;TD&gt;var2&lt;/TD&gt;&lt;TD&gt;var3&lt;/TD&gt;&lt;TD&gt;var4&lt;/TD&gt;&lt;TD&gt;var5&lt;/TD&gt;&lt;TD&gt;var6&lt;/TD&gt;&lt;TD&gt;var7&lt;/TD&gt;&lt;TD&gt;var8&lt;/TD&gt;&lt;TD&gt;var9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;vanguard, fund, is-good;and not bad;class A&lt;/TD&gt;&lt;TD&gt;vanguard&lt;/TD&gt;&lt;TD&gt;fund&lt;/TD&gt;&lt;TD&gt;is&lt;/TD&gt;&lt;TD&gt;good&lt;/TD&gt;&lt;TD&gt;and&lt;/TD&gt;&lt;TD&gt;not&lt;/TD&gt;&lt;TD&gt;bad&lt;/TD&gt;&lt;TD&gt;class&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;vang-uard, fund&amp;nbsp;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;vang&lt;/TD&gt;&lt;TD&gt;uard&lt;/TD&gt;&lt;TD&gt;fund&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bad/ thi:ngs happen: class A&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/TD&gt;&lt;TD&gt;bad&lt;/TD&gt;&lt;TD&gt;thi&lt;/TD&gt;&lt;TD&gt;ngs&lt;/TD&gt;&lt;TD&gt;happen&lt;/TD&gt;&lt;TD&gt;class&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I got over 1 million rows for &lt;SPAN&gt;var_name so&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;I just want to do it efficiently.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Anybody can give some help?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It will be more than welcome.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 07:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/461936#M117533</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2018-05-14T07:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: parsing characters with multiple delimters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/461945#M117535</link>
      <description>&lt;P&gt;Well, first off some advice, its not a great idea to have variables going across, there could be hundreds and your code then needs to know how many of them etc.&amp;nbsp; Makes life far more difficult.&amp;nbsp; What I would do is output at each delimiter to a new obs, then transpose if needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have
  do i=1 to countw(var_name," ,-;:");
    word=scan(var_name,i," ,-;:");
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;This will give you a long table with word containing the right amount of observations (i.e. if you transpose then there will be many blank variables as not all will have max number of words).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way is to find the max number of words up front and then create an array from that, maybe:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  select count(max(countw(var_name," ,-/;:"))) 
  into :marry
  from have;
quit;

data want;
  set have;
  array max_elem{&amp;amp;marry.} $200.;
  do i=1 to countw(var_name," ,-/;:");&lt;BR /&gt;    max_elem{i}=scan(var_name,i," ,-/;:");&lt;BR /&gt;  end;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 07:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/461945#M117535</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-14T07:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: parsing characters with multiple delimters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/461948#M117537</link>
      <description>&lt;P&gt;Would definitely make this data set long. If that is not an option, do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt;length var_name $200;&lt;BR /&gt;var_name="vanguard, fund, is-good;and not bad;class A";output;&lt;BR /&gt;var_name=" vang-uard, fund";output;&lt;BR /&gt;var_name="bad/ thi:ngs happen: class A";output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt; select max(countw(var_name," ,-/;:"))&lt;BR /&gt; into :maxnum&lt;BR /&gt; from have;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;maxnum.;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt; set have;&lt;BR /&gt; delims = ',-/:; ';&lt;BR /&gt; numWords = countw(var_name, delims);&lt;BR /&gt; array var{&amp;amp;maxnum.} $;&lt;BR /&gt; do i=1 to dim(var);&lt;BR /&gt; var[i] = scan(var_name, i, delims);&lt;BR /&gt; end;&lt;BR /&gt; drop delims numWords i;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 09:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/461948#M117537</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-05-14T09:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: parsing characters with multiple delimters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/462018#M117545</link>
      <description>Perfect really thank you!</description>
      <pubDate>Mon, 14 May 2018 12:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-characters-with-multiple-delimters/m-p/462018#M117545</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2018-05-14T12:35:15Z</dc:date>
    </item>
  </channel>
</rss>

