<?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 column into multiple columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887067#M350510</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID X $20.;
cards;
111 RF201|RF205|RF209
222 RF201|RF211
333 RF304
;
Run;

data temp;
 set have;
 value=1;
 do i=1 to countw(X,'|');
   temp=scan(X,i,'|');output;
 end;
keep id temp value;
run;
proc transpose data=temp out=temp2(drop=_name_);
by id;
var value;
id temp;
run;
proc stdize data=temp2 out=want reponly missing=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 31 Jul 2023 09:43:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-07-31T09:43:05Z</dc:date>
    <item>
      <title>Split column into multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887062#M350507</link>
      <description>&lt;P&gt;Hello, For each customer ID there is a column that contain reasons for overide. This field called X (reasons for overide) is concatenation of strings. My question: What is the way to create the want data set? The want data set will contain multiple new columns (Each overide reason will have column ) and will get binary values 1/0&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID X $20.;
cards;
111 RF201|RF205|RF209
222 RF201|RF211
333 RF304
;
Run;

data want;
input ID RF201 RF205 RF209 RF211 RF304 ;
datalines;
111 1 1 1 0 0
222 1 0 0 1 0
333 0 0 0 0 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 07:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887062#M350507</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-07-31T07:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Split column into multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887067#M350510</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID X $20.;
cards;
111 RF201|RF205|RF209
222 RF201|RF211
333 RF304
;
Run;

data temp;
 set have;
 value=1;
 do i=1 to countw(X,'|');
   temp=scan(X,i,'|');output;
 end;
keep id temp value;
run;
proc transpose data=temp out=temp2(drop=_name_);
by id;
var value;
id temp;
run;
proc stdize data=temp2 out=want reponly missing=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 09:43:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887067#M350510</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-07-31T09:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Split column into multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887068#M350511</link>
      <description>&lt;P&gt;another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data split;
   set have;

   length rf $ 5;

   do i = 1 to countw(x, '|');
      rf = scan(x, i, '|');
      output;
   end;

   drop x i;
run;


proc sql noprint;
   select distinct rf
      into :rf_list separated by ' '
      from work.split;
quit;


data want;
   set split;
   by id;

   length &amp;amp;rf_list. 8;
   retain &amp;amp;rf_list.;

   array rf_list &amp;amp;rf_list.;

   if first.id then do;
      do i = 1 to dim(rf_list);
         rf_list[i] = 0;
      end;
   end;

   rf_list[findw("&amp;amp;rf_list", rf, ' ', 'ets')] = 1;

   if last.id then output;

   drop i rf;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 09:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887068#M350511</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-07-31T09:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Split column into multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887077#M350514</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;When I add one more row with missing value (X column) then I recieve a warning&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: 1 observations omitted due to missing ID values.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is the way to prevent this warning?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input CustID X $20.;
cards;
111 RF201|RF205|RF209
222 RF201|RF211
333 RF304
444
;
Run;

/****Wide To Long****/
data temp;
set have;
value=1;
do i=1 to countw(X,'|');
temp=scan(X,i,'|');
output;
end;
keep CustID temp value;
run;

/****Long To Wide****/
proc transpose data=temp out=temp2(drop=_name_);
by CustID;
var value;
id temp;
run;
/*WARNING: 1 observations omitted due to missing ID values.*/


/***Convert Missing into zero***/
proc stdize data=temp2 out=want reponly missing=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jul 2023 10:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887077#M350514</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2023-07-31T10:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Split column into multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887082#M350516</link>
      <description>&lt;P&gt;If you know in advance the names you want to use for the flag variables (and the names matches the text you have in your X variable) you can just use an ARRAY and the FINDW() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID X $20.;
cards;
111 RF201|RF205|RF209
222 RF201|RF211
333 RF304
444
;

data want;
  set have;
  array flags RF201 RF205 RF209 RF211 RF304;
  do over flags;
    flags=0&amp;lt;findw(x,vname(flags),'|','ti');
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 11:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887082#M350516</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-31T11:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Split column into multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887275#M350556</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
OK.It looks like you have some unexpected data.
*/
Data have;
input CustID X $20.;
cards;
111 RF201|RF205|RF209
222 RF201|RF211
333 RF304
444
;
Run;

/****Wide To Long****/
data temp;
set have(where=(X is not missing));
value=1;
do i=1 to countw(X,'|');
temp=scan(X,i,'|');
output;
end;
keep CustID temp value;
run;

/****Long To Wide****/
proc transpose data=temp out=temp2(drop=_name_) ;
by CustID;
var value;
id temp;
run;
/*Combine  ID with missing X back.*/
data temp2;
 set temp2  have(where=(X is missing));
 drop X;
run;


/***Convert Missing into zero***/
proc stdize data=temp2 out=want reponly missing=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Aug 2023 11:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-column-into-multiple-columns/m-p/887275#M350556</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-01T11:45:03Z</dc:date>
    </item>
  </channel>
</rss>

