<?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: Split out Delimiter Character String and count in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697627#M213227</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data NewData;

length ReasonCode $255.;

Input REASONCODE $;

datalines;
aaa:bbb:ccc:ddd:eee
eee:aaa:fff:mmm
ddd:rrr:yyy:zzz
xxx:ggg
;

run;

data temp;
 set newdata;
 do _n_=1 to countw(ReasonCode,':');
  temp=scan(ReasonCode,_n_,':');
  output;
 end;
run;
proc freq data=temp ;
 tables ReasonCode*temp/noprint sparse out=temp2(drop=percent);;
run;

proc transpose data=temp2 out=want(drop=_:);
 by ReasonCode;
 id temp;
 var count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 09 Nov 2020 14:37:36 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-11-09T14:37:36Z</dc:date>
    <item>
      <title>Split out Delimiter Character String and count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697625#M213225</link>
      <description>&lt;P&gt;Good afternoon All.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with a singular column which contains a variety of character strings delimited by a colon.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NewData;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ReasonCode &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$255.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;Input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; REASONCODE $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;aaa:bbb:ccc:ddd:eee&lt;/P&gt;&lt;P&gt;eee:aaa:fff:mmm&lt;/P&gt;&lt;P&gt;ddd:rrr:yyy:zzz&lt;/P&gt;&lt;P&gt;xxx:ggg&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No what I want to do is split out the string by the delimiter which I believe I had as per below.&amp;nbsp; This creates Var1, 2, 3 etc from the string and those are populated with aaa, bbb, ccc etc&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NextStep ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NewData;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; var(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;40&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$45.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;until&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; (scan(ReasonCode,i,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;":"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) eq &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;""&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;var(i)=scan(ReasonCode,i,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;":"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thus creating the following dataset:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;REASONCODE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1&amp;nbsp; var2&amp;nbsp; var3&amp;nbsp; var4&amp;nbsp; var5&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&amp;nbsp;aaa&amp;nbsp;&amp;nbsp; bbb&amp;nbsp;&amp;nbsp; ccc&amp;nbsp;&amp;nbsp; ddd&amp;nbsp;&amp;nbsp; eee&lt;BR /&gt;eee:aaa:fff:mmm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eee&amp;nbsp;&amp;nbsp; aaa&amp;nbsp;&amp;nbsp; fff&amp;nbsp;&amp;nbsp; mmm&amp;nbsp;&lt;BR /&gt;ddd:rrr:yyy:zzz&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ddd&amp;nbsp;&amp;nbsp; rrr&amp;nbsp;&amp;nbsp; yyy&amp;nbsp;&amp;nbsp; zzz&amp;nbsp;&lt;BR /&gt;xxx:ggg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xxx&amp;nbsp;&amp;nbsp; ggg&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Now where I'm getting stuck on logic/coding is that I want to take every iteration of new variable such as aaa, bbb, ccc and make it a Column Heading and count the number of times this appears in the data?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;REASONCODE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; aaa&amp;nbsp;bbb&amp;nbsp;ccc&amp;nbsp;ddd&amp;nbsp;eee&amp;nbsp;ggg&amp;nbsp;fff&amp;nbsp;mmm&amp;nbsp;rrr&amp;nbsp;xxx&amp;nbsp;yyy&amp;nbsp;zzz&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&lt;BR /&gt;eee:aaa:fff:mmm&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&lt;BR /&gt;ddd:rrr:yyy:zzz&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;xxx:ggg&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp; 0&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Appreciate any help that you can provide.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 14:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697625#M213225</guid>
      <dc:creator>Doyleuk1983</dc:creator>
      <dc:date>2020-11-09T14:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: Split out Delimiter Character String and count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697627#M213227</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data NewData;

length ReasonCode $255.;

Input REASONCODE $;

datalines;
aaa:bbb:ccc:ddd:eee
eee:aaa:fff:mmm
ddd:rrr:yyy:zzz
xxx:ggg
;

run;

data temp;
 set newdata;
 do _n_=1 to countw(ReasonCode,':');
  temp=scan(ReasonCode,_n_,':');
  output;
 end;
run;
proc freq data=temp ;
 tables ReasonCode*temp/noprint sparse out=temp2(drop=percent);;
run;

proc transpose data=temp2 out=want(drop=_:);
 by ReasonCode;
 id temp;
 var count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 14:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697627#M213227</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-09T14:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Split out Delimiter Character String and count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697632#M213229</link>
      <description>&lt;P&gt;If the variable order is not important&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data NewData;
length ReasonCode $255.;
Input REASONCODE $;
datalines;
aaa:bbb:ccc:ddd:eee
eee:aaa:fff:mmm
ddd:rrr:yyy:zzz
xxx:ggg
;
run;

data temp;
   set NewData;
   retain c 1;
   do i = 1 to countw(ReasonCode, ':');
      w = scan(ReasonCode, i, ':');
      output;
   end;
run;

proc transpose data=temp out=want(drop=_:);
   by ReasonCode notsorted;
   id w;
   var c;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 14:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697632#M213229</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-09T14:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Split out Delimiter Character String and count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697654#M213238</link>
      <description>I added in more data and not sure the solution is summing up correctly;&lt;BR /&gt;&lt;BR /&gt;Data NewData;&lt;BR /&gt;length RSAP_ReasonCode $255.;&lt;BR /&gt;Input RSAP_REASONCODE $;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&lt;BR /&gt;eee:aaa:fff:mmm&lt;BR /&gt;ddd:rrr:yyy:zzz&lt;BR /&gt;xxx:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:fff&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:hhh&lt;BR /&gt;ddd:rrr:yyy:zzz&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&lt;BR /&gt;eee:aaa:fff:mmm&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 09 Nov 2020 16:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697654#M213238</guid>
      <dc:creator>Doyleuk1983</dc:creator>
      <dc:date>2020-11-09T16:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Split out Delimiter Character String and count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697657#M213240</link>
      <description>If I were to add in further data as follows:&lt;BR /&gt;Data NewData;&lt;BR /&gt;length RSAP_ReasonCode $255.;&lt;BR /&gt;Input RSAP_REASONCODE $;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&lt;BR /&gt;eee:aaa:fff:mmm&lt;BR /&gt;ddd:rrr:yyy:zzz&lt;BR /&gt;xxx:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:fff&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:hhh&lt;BR /&gt;ddd:rrr:yyy:zzz&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&lt;BR /&gt;eee:aaa:fff:mmm&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;the solution doesn't work and produces:&lt;BR /&gt;&lt;BR /&gt;ERROR: The ID value "aaa" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "bbb" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "ccc" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "ddd" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "eee" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "ggg" occurs twice in the same BY group.&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Nov 2020 16:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697657#M213240</guid>
      <dc:creator>Doyleuk1983</dc:creator>
      <dc:date>2020-11-09T16:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Split out Delimiter Character String and count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697668#M213249</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356227"&gt;@Doyleuk1983&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;If I were to add in further data as follows:&lt;BR /&gt;Data NewData;&lt;BR /&gt;length RSAP_ReasonCode $255.;&lt;BR /&gt;Input RSAP_REASONCODE $;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&lt;BR /&gt;eee:aaa:fff:mmm&lt;BR /&gt;ddd:rrr:yyy:zzz&lt;BR /&gt;xxx:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:fff&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:hhh&lt;BR /&gt;ddd:rrr:yyy:zzz&lt;BR /&gt;aaa:bbb:ccc:ddd:eee&lt;BR /&gt;eee:aaa:fff:mmm&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;aaa:bbb:ccc:ddd:eee:ggg&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;the solution doesn't work and produces:&lt;BR /&gt;&lt;BR /&gt;ERROR: The ID value "aaa" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "bbb" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "ccc" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "ddd" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "eee" occurs twice in the same BY group.&lt;BR /&gt;ERROR: The ID value "ggg" occurs twice in the same BY group.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot have duplicate ID for BY values unless you use the LET option on the procedure.&lt;/P&gt;
&lt;P&gt;Not going to say that will fix everything but the errors will go away and you can examine the outputl&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 16:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-out-Delimiter-Character-String-and-count/m-p/697668#M213249</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-09T16:50:56Z</dc:date>
    </item>
  </channel>
</rss>

