<?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: Separate data from one column to different others in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174393#M33509</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK . It would be better if you could post some sample data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input x $40. ;
cards;
DS
DS_TL_PA
PA_TL
OTHER_WHATEVER
WHY_OTHER
;
run;
data temp(drop=i x);
 set have;
 length id v $ 40;
 n+1;
 if find(x,'OTHER','i') then do;
 id='OTHER'; v=x; output;
 end;
else do;
do i=1 to countw(x,'_');
&amp;nbsp; id=scan(x,i,'_');v=id;output;
 end;
end;
run;
proc transpose data=temp out=want(drop=_:) ;
by n;
var v;
id id;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Aug 2014 12:09:22 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-08-28T12:09:22Z</dc:date>
    <item>
      <title>Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174388#M33504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've a sas-file with one column left (originally coming from a csv-file) but the column consists different words separated by "_". Depending on the line in the file there is a different amount of used words and a different words are used. I would like to make different columns from this entry so that each column consists only one word and only has content if the word is available in the original file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I have:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="149" style="border: 1px solid rgb(0, 0, 0); width: 201px; height: 150px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Content&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DS_TL_PA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;PA_TL&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and I would like:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="107" style="border: 1px solid rgb(0, 0, 0); width: 294px; height: 109px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;DS&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;TL&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;PA&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DS&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DS&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;TL&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;PA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;TL&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;PA&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does someone has an idea which function I need to use for this or how I can do this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Aug 2014 12:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174388#M33504</guid>
      <dc:creator>annelies_wiv</dc:creator>
      <dc:date>2014-08-25T12:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174389#M33505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
input x $ ;
cards;
DS
DS_TL_PA
PA_TL
;
run;
data temp(drop=i x);
 set have;
 n+1;
 do i=1 to countw(x,'_');
&amp;nbsp; v=scan(x,i,'_');output;
 end;
run;
proc transpose data=temp out=want(drop=_:) ;
by n;
var v;
id v;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Aug 2014 13:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174389#M33505</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-25T13:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174390#M33506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input text $50.;&lt;BR /&gt;datalines;&lt;BR /&gt;DS_XYZ_KO&lt;BR /&gt;DS_TL_PA &lt;BR /&gt;PA_TL &lt;BR /&gt;SA_KO&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data int1;&lt;BR /&gt;set have nobs=last;&lt;BR /&gt;do i=1 to last while(scan(text,i,"_") ne "");&lt;BR /&gt;sepvar=scan(text,i,"_");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct sepvar, sepvar into :allvars separated by " char(10)," ,&amp;nbsp; :arrvar separated by " " from int1;&lt;BR /&gt;create table int2 (&amp;amp;allvars char(10));&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;arrvar;&lt;/P&gt;&lt;P&gt;data want(drop=text i j );&lt;BR /&gt;set have ; &lt;BR /&gt;array all{*} $20 &amp;amp;arrvar ;&lt;BR /&gt;do i=1 to count(text,"_")+1;&lt;BR /&gt; do until (vname(all{j}) = scan(text,i,"_")); &lt;BR /&gt; j+1;&lt;BR /&gt; end;&lt;BR /&gt;call vname(all{j},all{j}); &lt;BR /&gt;j=0;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Aug 2014 13:59:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174390#M33506</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-08-25T13:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174391#M33507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot Ksharp!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Only one problem left: I have as answer the text containing DS, TL, PA and so on but also some answers containing "other" and then the explanation why the answer "other" was chosen. Is there are possibility to group them all together in one column? The exact text doesn't matter for this, only the fact that the text contains the word "other" (as I want to calculate the frequency of the different answers).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 15:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174391#M33507</guid>
      <dc:creator>annelies_wiv</dc:creator>
      <dc:date>2014-08-27T15:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174392#M33508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Loko for your help!&lt;/P&gt;&lt;P&gt;Although I used Ksharp's answer as it was easier for me to understand...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Aug 2014 15:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174392#M33508</guid>
      <dc:creator>annelies_wiv</dc:creator>
      <dc:date>2014-08-27T15:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174393#M33509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK . It would be better if you could post some sample data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input x $40. ;
cards;
DS
DS_TL_PA
PA_TL
OTHER_WHATEVER
WHY_OTHER
;
run;
data temp(drop=i x);
 set have;
 length id v $ 40;
 n+1;
 if find(x,'OTHER','i') then do;
 id='OTHER'; v=x; output;
 end;
else do;
do i=1 to countw(x,'_');
&amp;nbsp; id=scan(x,i,'_');v=id;output;
 end;
end;
run;
proc transpose data=temp out=want(drop=_:) ;
by n;
var v;
id id;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 12:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174393#M33509</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-28T12:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to different others</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174394#M33510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, it worked (and even better than I expected as the complete text is saved)!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 08:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-different-others/m-p/174394#M33510</guid>
      <dc:creator>annelies_wiv</dc:creator>
      <dc:date>2014-08-29T08:31:21Z</dc:date>
    </item>
  </channel>
</rss>

