<?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 Splitting variable into multiple rows in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16237#M2924</link>
    <description>I have a variable that has a list of people delimited by "--".  I want to seperate each person and make each one a row so I can sort then get a distinct list of people.&lt;BR /&gt;
&lt;BR /&gt;
example data&lt;BR /&gt;
Bob Jones--Fred Smith&lt;BR /&gt;
William Feek--Cindy Simpson--Abigail Wii&lt;BR /&gt;
David Davidson&lt;BR /&gt;
Chris Testers--Mindy Sohow&lt;BR /&gt;
&lt;BR /&gt;
I need this as the output&lt;BR /&gt;
Abigail Wii&lt;BR /&gt;
Bob Jones&lt;BR /&gt;
Chris Testers&lt;BR /&gt;
Cindy Simpson&lt;BR /&gt;
David Davidson&lt;BR /&gt;
Fred Smith&lt;BR /&gt;
Mindy Sohow&lt;BR /&gt;
William Feek&lt;BR /&gt;
&lt;BR /&gt;
I was looking at using the scan function but I'm not sure how to cycle through the string.</description>
    <pubDate>Fri, 17 Jun 2011 14:24:46 GMT</pubDate>
    <dc:creator>jerry898969</dc:creator>
    <dc:date>2011-06-17T14:24:46Z</dc:date>
    <item>
      <title>Splitting variable into multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16237#M2924</link>
      <description>I have a variable that has a list of people delimited by "--".  I want to seperate each person and make each one a row so I can sort then get a distinct list of people.&lt;BR /&gt;
&lt;BR /&gt;
example data&lt;BR /&gt;
Bob Jones--Fred Smith&lt;BR /&gt;
William Feek--Cindy Simpson--Abigail Wii&lt;BR /&gt;
David Davidson&lt;BR /&gt;
Chris Testers--Mindy Sohow&lt;BR /&gt;
&lt;BR /&gt;
I need this as the output&lt;BR /&gt;
Abigail Wii&lt;BR /&gt;
Bob Jones&lt;BR /&gt;
Chris Testers&lt;BR /&gt;
Cindy Simpson&lt;BR /&gt;
David Davidson&lt;BR /&gt;
Fred Smith&lt;BR /&gt;
Mindy Sohow&lt;BR /&gt;
William Feek&lt;BR /&gt;
&lt;BR /&gt;
I was looking at using the scan function but I'm not sure how to cycle through the string.</description>
      <pubDate>Fri, 17 Jun 2011 14:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16237#M2924</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2011-06-17T14:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting variable into multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16238#M2925</link>
      <description>Use a DO / END loop and use COUNTW function to count the words (in your &lt;EXPRESSION&gt; part of the DO).  You will have a LENGTH/ATTRIB, a SAS assignment where SCAN is used to parse the data-string, and an OUTPUT statement (minimum) in the DO/END code paragraph.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/EXPRESSION&gt;</description>
      <pubDate>Fri, 17 Jun 2011 14:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16238#M2925</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-06-17T14:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting variable into multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16239#M2926</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Try using the count() function in BASE SAS.&lt;BR /&gt;
&lt;BR /&gt;
data test (keep=name);&lt;BR /&gt;
        /* This a single string with multiple delimited names */&lt;BR /&gt;
	x='Bob Jones--Fred Smith--William Feek--Cindy Simpson--Abigail Wii--David Davidson--Chris Testers--Mindy Sohow';&lt;BR /&gt;
&lt;BR /&gt;
        /* Count number of times the delimiter occurs */&lt;BR /&gt;
	count= count(x,'--');&lt;BR /&gt;
	put count=;&lt;BR /&gt;
&lt;BR /&gt;
        /* Output each name to a separate observation */&lt;BR /&gt;
	do i=1 to (count+1);&lt;BR /&gt;
		name = scan(x,i,'--');&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=test; run;&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps,&lt;BR /&gt;
Ahmed</description>
      <pubDate>Fri, 17 Jun 2011 14:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16239#M2926</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2011-06-17T14:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting variable into multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16240#M2927</link>
      <description>Scott,&lt;BR /&gt;
&lt;BR /&gt;
You are the best.  This is what I came up with and it seems to work.&lt;BR /&gt;
&lt;BR /&gt;
data t ;&lt;BR /&gt;
	set pep (obs=5);	&lt;BR /&gt;
	cnt = COUNTW(people, '--') ;&lt;BR /&gt;
	i=0;&lt;BR /&gt;
	do while(i &amp;lt; cnt);&lt;BR /&gt;
  	 i+1;&lt;BR /&gt;
  	 x = scan(people,i,'--') ;&lt;BR /&gt;
	 output;&lt;BR /&gt;
 	end; &lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
Do you see any issues with the way i'm doing it?&lt;BR /&gt;
&lt;BR /&gt;
Thank you again</description>
      <pubDate>Fri, 17 Jun 2011 14:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16240#M2927</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2011-06-17T14:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting variable into multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16241#M2928</link>
      <description>Ahmed,&lt;BR /&gt;
&lt;BR /&gt;
thank you as well your solution works as well.&lt;BR /&gt;
&lt;BR /&gt;
Thank you</description>
      <pubDate>Fri, 17 Jun 2011 14:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-variable-into-multiple-rows/m-p/16241#M2928</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2011-06-17T14:52:22Z</dc:date>
    </item>
  </channel>
</rss>

