<?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: Creating binary variables from categories in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702716#M215244</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
	set have;
	by id;
	length d_cat $10.;
	retain d_cat ;

		array cat[3] $ a_category	b_category	c_category;

	if first.id then	call missing(d_cat);
	d_cat=cats(d_cat,D_name);

	if last.id then
		do;
			do _n_=1 to dim(cat);
				if find(d_cat,scan(vname(cat[_n_]),1,'_')) then
					cat[_n_]='yes';
				else cat[_n_]='no';
			end;
			output;
		end;
	drop D_name;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Dec 2020 03:14:21 GMT</pubDate>
    <dc:creator>r_behata</dc:creator>
    <dc:date>2020-12-01T03:14:21Z</dc:date>
    <item>
      <title>Creating binary variables from categories</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702681#M215229</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a dataset with a variable that has different categories. I need to create a binary (yes/no) for each category.&lt;/P&gt;
&lt;P&gt;Data Have:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl63" style="height: 15.0pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="width: 48pt;"&gt;D_name&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl63"&gt;a,b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;a,b,c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;2&lt;/TD&gt;
&lt;TD class="xl63"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;3&lt;/TD&gt;
&lt;TD class="xl63"&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;4&lt;/TD&gt;
&lt;TD class="xl63"&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl63" style="height: 15.0pt;"&gt;4&lt;/TD&gt;
&lt;TD class="xl63"&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want:&lt;/P&gt;
&lt;TABLE width="286"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;ID&lt;/TD&gt;
&lt;TD width="74"&gt;a_category&lt;/TD&gt;
&lt;TD width="75"&gt;b_category&lt;/TD&gt;
&lt;TD width="73"&gt;c_category&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;no&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;TD&gt;no&lt;/TD&gt;
&lt;TD&gt;yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 01:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702681#M215229</guid>
      <dc:creator>newsas007</dc:creator>
      <dc:date>2020-12-01T01:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating binary variables from categories</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702685#M215232</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID	D_name $;
cards;
1	a
1	a,b
2	a
2	a,b,c
2	a
3	a
3	b
3	c
4	a
4	c
;

data want;
 do until(last.id);
  set have;
  by id;
  array t $3  a_category	b_category	c_category ;
  array j(3) $ _temporary_ ('a','b','c') ;
  do _n_=1 to dim(j);
   if t(_n_) ne 'yes' then  t(_n_)=ifc( index(d_name,strip(j(_n_))),'yes','no');
  end;
 end;
 drop d_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 01:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702685#M215232</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-01T01:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating binary variables from categories</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702716#M215244</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
	set have;
	by id;
	length d_cat $10.;
	retain d_cat ;

		array cat[3] $ a_category	b_category	c_category;

	if first.id then	call missing(d_cat);
	d_cat=cats(d_cat,D_name);

	if last.id then
		do;
			do _n_=1 to dim(cat);
				if find(d_cat,scan(vname(cat[_n_]),1,'_')) then
					cat[_n_]='yes';
				else cat[_n_]='no';
			end;
			output;
		end;
	drop D_name;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Dec 2020 03:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-binary-variables-from-categories/m-p/702716#M215244</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2020-12-01T03:14:21Z</dc:date>
    </item>
  </channel>
</rss>

