<?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: How to split one column into two based on a delimiter? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611535#M178242</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303436"&gt;@Nafin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an alternative to the scan function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Address1:&amp;nbsp;looks for the pattern "one or many spaces followed by a | and then any character at the end of the string (\s+\|.*$)" and replace it by nothing&lt;/P&gt;
&lt;P&gt;Address2:&amp;nbsp;look for either:&lt;/P&gt;
&lt;P&gt;- a string without symbol | ([^\|]*)&lt;/P&gt;
&lt;P&gt;- the following pattern: any character at the beginning of the string followed by a | and then one or more spaces (^.*\|\s+)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set address;
	address1 = prxchange('s/\s*\|[^\|]*$//',1,address);
	address2 = prxchange('s/^[^\|]*\|\s*|[^\|]*//',1,address);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Dec 2019 09:08:22 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2019-12-13T09:08:22Z</dc:date>
    <item>
      <title>How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611511#M178231</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have one column with addresses and a delimiter which I would like to split into two columns based on the delimiter |.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I have looks like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Addresses I have&lt;/TD&gt;&lt;TD&gt;Addresses I want&lt;/TD&gt;&lt;TD&gt;More Addresses I want&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1 Dexter Ln&lt;/TD&gt;&lt;TD&gt;1 Dexter Ln&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;87 N Main Ave | Suite B&lt;/TD&gt;&lt;TD&gt;87 N Main Ave&lt;/TD&gt;&lt;TD&gt;Suite B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;46 Kelly Ave | Apt 4&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;46 Kelly Ave&lt;/TD&gt;&lt;TD&gt;Apt 4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;616 Park Ave&lt;/TD&gt;&lt;TD&gt;616 Park Ave&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;243 Morris St | #B64&lt;/TD&gt;&lt;TD&gt;243 Morris St&lt;/TD&gt;&lt;TD&gt;#B64&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;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 04:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611511#M178231</guid>
      <dc:creator>Nafin</dc:creator>
      <dc:date>2019-12-13T04:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611513#M178233</link>
      <description>&lt;P&gt;Hi, Nafin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how about this&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 address;
  length address $200;
  infile datalines truncover;
  input address $ 1-200;
datalines;
1 Dexter Ln
87 N Main Ave | Suite B
46 Kelly Ave | Apt 4
616 Park Ave
243 Morris St | #B64
;
run;

data address2;
  set address;
  if find(address,'|')&amp;gt;0 then do;
    address1=strip(substr(address,1,find(address,'|')-1));
    address2=strip(substr(address,find(address,'|')+1));
  end; else
  do;
    address1=address;
    address2='';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Although premise that delimiter is only one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 05:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611513#M178233</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2019-12-13T05:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611523#M178235</link>
      <description>&lt;P&gt;Use the scan() function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
address1 = scan(address,1,'|');
address2 = scan(address,2,'|');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 07:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611523#M178235</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-13T07:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611535#M178242</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303436"&gt;@Nafin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an alternative to the scan function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Address1:&amp;nbsp;looks for the pattern "one or many spaces followed by a | and then any character at the end of the string (\s+\|.*$)" and replace it by nothing&lt;/P&gt;
&lt;P&gt;Address2:&amp;nbsp;look for either:&lt;/P&gt;
&lt;P&gt;- a string without symbol | ([^\|]*)&lt;/P&gt;
&lt;P&gt;- the following pattern: any character at the beginning of the string followed by a | and then one or more spaces (^.*\|\s+)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set address;
	address1 = prxchange('s/\s*\|[^\|]*$//',1,address);
	address2 = prxchange('s/^[^\|]*\|\s*|[^\|]*//',1,address);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 09:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611535#M178242</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-13T09:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611773#M178382</link>
      <description>&lt;P&gt;Thank you Kawakami! It works, however, I noticed that my dataset contain some records with more than one delimiter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help though.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nafin&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 06:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611773#M178382</guid>
      <dc:creator>Nafin</dc:creator>
      <dc:date>2019-12-14T06:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611774#M178383</link>
      <description>Thank you ed_sas_member for the code and explanation! This method works.&lt;BR /&gt;&lt;BR /&gt;Nafin&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for your help though.&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Nafin</description>
      <pubDate>Sat, 14 Dec 2019 06:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611774#M178383</guid>
      <dc:creator>Nafin</dc:creator>
      <dc:date>2019-12-14T06:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611776#M178384</link>
      <description>&lt;P&gt;Thank you KurtBremser! It works!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although your code works perfectly, I'm little puzzled because I&amp;nbsp;tried the Scan function before and it didn't work for me. When I used it, it allowed me to copy over only a single word to the new column "Address1" (and I put 1 in the second argument within the parenthesis in the scan function exactly like you).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How come your code allows to copy to the new column "Address1" all the words that are positioned before the delimiter even though you use 1 in the second argument of the scan function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nafin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 06:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611776#M178384</guid>
      <dc:creator>Nafin</dc:creator>
      <dc:date>2019-12-14T06:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611777#M178385</link>
      <description>&lt;P&gt;That's because I use the third argument to set the delimiter. Without the third argument, blanks are considered as delimiters.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 07:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611777#M178385</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-14T07:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611778#M178386</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303436"&gt;@Nafin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're welcome&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 09:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/611778#M178386</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-14T09:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/612029#M178504</link>
      <description>Thank you for the clarification!&lt;BR /&gt;&lt;BR /&gt;Nafin</description>
      <pubDate>Mon, 16 Dec 2019 14:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/612029#M178504</guid>
      <dc:creator>Nafin</dc:creator>
      <dc:date>2019-12-16T14:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/718084#M222157</link>
      <description>&lt;P&gt;This worked really well! I need to extend the idea. I have a field where I don't know the number of delimited values (in one case up to 800 times).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case, I have a column named "Group":&lt;/P&gt;&lt;P&gt;&amp;nbsp;- Row 1 has the values of "a, x, r, f"&lt;/P&gt;&lt;P&gt;&amp;nbsp;- Row 2 has the values of "r, b, a, q, g, 8"&lt;/P&gt;&lt;P&gt;&amp;nbsp;- Row 3 has the value of "s"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like it to create:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Row 1 New Column of Group_1 with the value of "a"&lt;/P&gt;&lt;P&gt;Row 1 New Column of Group_2 with the value of "x"&lt;/P&gt;&lt;P&gt;Row 1 New Column of Group_3 with the value of "r"&lt;/P&gt;&lt;P&gt;Row 1 New Column of Group_4 with the value of "f"&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;Row 3 column created above Group_1 with the value of "s" and all other New Columns would be blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying a "do" statement using the scan to iterate up the Goup_# and then use it again as the scan number, but it's alluding me. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 00:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/718084#M222157</guid>
      <dc:creator>jahunter</dc:creator>
      <dc:date>2021-02-10T00:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to split one column into two based on a delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/718139#M222188</link>
      <description>&lt;P&gt;If you have an arbitrary number of values, it is best to split vertically.&lt;/P&gt;
&lt;P&gt;Create a single variable, and output for every item. Keep the new variable, any variables you need for identification, and the counter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A long dataset is always easier to use than a wide one.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 07:34:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-one-column-into-two-based-on-a-delimiter/m-p/718139#M222188</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-10T07:34:07Z</dc:date>
    </item>
  </channel>
</rss>

