<?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 do i split by comma and transpose? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538593#M148282</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;. Thanks for the code. It is working perfectly. However, would it be able to tweak to cater for Scenario 2 that i just put in in my first post?&lt;/P&gt;</description>
    <pubDate>Tue, 26 Feb 2019 08:56:46 GMT</pubDate>
    <dc:creator>imdickson</dc:creator>
    <dc:date>2019-02-26T08:56:46Z</dc:date>
    <item>
      <title>How do i split by comma and transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538294#M148170</link>
      <description>&lt;P&gt;Hi everyone. I was given a data in below structure:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name    Age Hobby                                  Color
Ben       12    Movie, Study                        Blue, Red
Fenny     27   Jogging, Eating                   White, Red&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and was asked to convert into this format:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name  Age  Hobby  Color
Ben     12     Movie   Blue
Ben     12     Movie   Red
Ben     12     Study    Blue
Ben     12     Study    Red
Fenny  27    Jogging White
Fenny  27    Jogging Red
Fenny  27    Eating    White
Fenny  27    Eating    Red&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been doing research for the past 3 hours and i do not find any straight forward answer to that.&lt;/P&gt;&lt;P&gt;I was thinking to use below logic, which i havent tried yet as my work PC is not at home today.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;First step, find way to split the delimiter comma. Then, if first.name then populate the value in delimiter into column color and hobby.

However, I really cannot think of the proper script for that. Can anyone give some hint on the script needed? even if there is no full code is fine, as i just need some logic explanation.

data want;
set have;
if first.name then do;
     

end;

run;&lt;/CODE&gt;&lt;/PRE&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;&lt;P&gt;Scenario 2&lt;/P&gt;&lt;P&gt;I have another new file and i was asked to generate another output.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name    feeder_in    feeder_out   NickName
ABBA    1,2              A,B              ABBA
POLA    1,2              C,D,E          CONS POLA&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the desire output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name             feeder_final    
ABBA              1                
ABBA              2                 
ABBA              A
ABBA              B
POLA              1                 
POLA              2
CONS POLA         C
CONS POLA         D
CONS POLA         E&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is different from the earlier scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have clue for scenario 2?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 09:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538294#M148170</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-02-26T09:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do i split by comma and transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538296#M148172</link>
      <description>&lt;P&gt;For each record, count the number of hobbies, count the number of colors, and then for each color/hobby combination, output a new record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */

data want;
    set have;
    length newhobby newcolor $ 10;
    do i=1 to countw(hobby,',');
         do j=1 to countw(color,',');
              newhobby=scan(hobby,i,',');
              newcolor=scan(color,j,',');
              output;
         end;
    end;
    drop i j hobby color;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Feb 2019 15:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538296#M148172</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-25T15:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do i split by comma and transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538297#M148173</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have (rename=(hobby=hobby_old color=color_old));
do hc = 1 to countw(hobby_old,',');
  hobby = scan(hobby_old,hc,',');
  do cc = 1 to countw(color_old,',');
    color = scan(color_old,cc,',');
    output;
  end;
end;
drop color_old hobby_old hc cc:
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just two nested loops and use of countw() and scan().&lt;/P&gt;</description>
      <pubDate>Mon, 25 Feb 2019 15:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538297#M148173</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-25T15:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do i split by comma and transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538593#M148282</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;. Thanks for the code. It is working perfectly. However, would it be able to tweak to cater for Scenario 2 that i just put in in my first post?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 08:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538593#M148282</guid>
      <dc:creator>imdickson</dc:creator>
      <dc:date>2019-02-26T08:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do i split by comma and transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538618#M148288</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/63520"&gt;@imdickson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;. Thanks for the code. It is working perfectly. However, would it be able to tweak to cater for Scenario 2 that i just put in in my first post?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is so much easier to follow when new information is added at the bottom of the thread, rather than at the top. Could you please make Scenario 2 the next message in this thread?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 12:52:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538618#M148288</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-26T12:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do i split by comma and transpose?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538633#M148295</link>
      <description>&lt;P&gt;The principle is the same, just adapt the code.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 14:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-split-by-comma-and-transpose/m-p/538633#M148295</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-26T14:15:45Z</dc:date>
    </item>
  </channel>
</rss>

