<?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: Create New Variables based on Categorical Variable Value in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262151#M3856</link>
    <description>&lt;P&gt;&lt;EM&gt;&lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-create-dummy-variables-Categorical-Variables/m-p/258702/highlight/true#M13685" target="_blank"&gt;https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-create-dummy-variables-Categorical-Variables/m-p/258702/highlight/true#M13685&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I wrote a post on this recently that may be helpful. I would use a code node in EM to do this.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Do you really need to do this in EM though? If it's a categorical variable that's usually how SAS treat's it, and you can specify the parameterization type in some procedures.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Ie if your proc allows for a CLASS variable then it will be dummy coded by default, though it may not be the method you want.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I'm assuming EM since you've posted in data mining. If you're using Base SAS this would still be applicable though.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2016 17:28:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-07T17:28:11Z</dc:date>
    <item>
      <title>Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262139#M3854</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am building a model which will be used to analyze changing datasets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to make an indicator or dummy variable for each value that appears in a list of a categorical variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2658i84DA6B713FE351E4/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Cat1.JPG" title="Cat1.JPG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I need it to be:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2659i7F9C7ED96BF569A5/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Cat2..JPG" title="Cat2..JPG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I absolutely cannot do anytype of hardcoding because the values of my Categorical variable will change constantly as new datasets are analyzed. I need a quick and reproducible code that can duplicate the process when the categorical variable takes new values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All help greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 17:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262139#M3854</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2016-04-07T17:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262150#M3855</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-create-dummy-variables-Categorical-Variables/m-p/258702/highlight/true#M13685" target="_blank"&gt;https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-create-dummy-variables-Categorical-Variables/m-p/258702/highlight/true#M13685&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I wrote a post on this recently that may be helpful. I would use a code node in EM to do this.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Do you really need to do this in EM though? If it's a categorical variable that's usually how SAS treat's it, and you can specify the parameterization type in some procedures.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Ie if your proc allows for a CLASS variable then it will be dummy coded by default, though it may not be the method you want.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I'm assuming EM since you've posted in data mining. If you're using Base SAS this would still be applicable though.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 17:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262150#M3855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-07T17:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262151#M3856</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-create-dummy-variables-Categorical-Variables/m-p/258702/highlight/true#M13685" target="_blank"&gt;https://communities.sas.com/t5/SAS-Statistical-Procedures/How-to-create-dummy-variables-Categorical-Variables/m-p/258702/highlight/true#M13685&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I wrote a post on this recently that may be helpful. I would use a code node in EM to do this.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Do you really need to do this in EM though? If it's a categorical variable that's usually how SAS treat's it, and you can specify the parameterization type in some procedures.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Ie if your proc allows for a CLASS variable then it will be dummy coded by default, though it may not be the method you want.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;I'm assuming EM since you've posted in data mining. If you're using Base SAS this would still be applicable though.&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 17:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262151#M3856</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-07T17:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262153#M3857</link>
      <description>&lt;P&gt;Though I knew little to zero about IML, I however still think IML can have a neat solution for this.&amp;nbsp;Following is my quick and dirty way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS VALIDVARNAME=ANY;

DATA HAVE;
	INPUT ID VAR $;
	CARDS;
1 ONE_1
2 TWO_2
3 THREE_3
;

PROC TRANSPOSE DATA=HAVE OUT=HAVE2(DROP=_NAME_);
	ID VAR;
	COPY ID VAR;
RUN;

DATA WANT;
	SET HAVE2;
	ARRAY V 'ONE_1'N--'THREE_3'N;

	DO OVER V;
		V=IFN(VAR=VNAME(V),1,0);
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Updated:&amp;nbsp;To cope non-V7 compliance variable names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 18:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262153#M3857</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-07T18:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262194#M3859</link>
      <description>&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the response. I'm still trying to make it work. This isn't part of my modeling process...but part of my data-set building/ cleaning process and yes, I do need a dummy variable for each individual occurance of the categorical variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having trouble getting this to work though.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 20:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262194#M3859</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2016-04-07T20:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262198#M3860</link>
      <description>&lt;P&gt;Hi Haikuo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the resposne.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know if this is exactly what I want to do. I need a code that will read the values of the categorical variable and then create a new variable with the name of the categorical variable. Since the categorical variable will be changing from one data set to the next, the values will be changing and thus, this "Hard coding" will fail to create the name and variable since a value that exists in one dataset will most definitely be different than the value in the next.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 20:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262198#M3860</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2016-04-07T20:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262206#M3861</link>
      <description>&lt;P&gt;The main issue of this dummy variable making is the transpose, to make it dynamic is rather trivial, is this update what you need?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS VALIDVARNAME=ANY;

DATA HAVE;
	INPUT ID VAR $;
	CARDS;
1 ONE_1
2 TWO_2
3 THREE_3
;

PROC SQL NOPRINT ;
SELECT VAR INTO :VAR SEPARATED BY ' ' FROM HAVE;
QUIT;

PROC TRANSPOSE DATA=HAVE OUT=HAVE2(DROP=_NAME_);
	ID VAR;
	COPY ID VAR;
RUN;

DATA WANT;
	SET HAVE2;
	ARRAY V &amp;amp;VAR.;

	DO OVER V;
		V=IFN(VAR=VNAME(V),1,0);
	END;
RUN;

 
 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 21:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262206#M3861</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-07T21:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262210#M3862</link>
      <description>&lt;P&gt;Haikuo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are a genius! I will now be able to sleep tonight.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so incredible much! You have no idea how helpful that was!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 21:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262210#M3862</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2016-04-07T21:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262268#M3863</link>
      <description>&lt;PRE&gt;
You are trying to get Design Matrix . 
Check this blog:

http://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html

DATA HAVE;
	INPUT ID VAR $;
	CARDS;
1 ONE_1
2 TWO_2
3 THREE_3
;
run;
data Temp ;
   set have;
   FakeY = 0;
run;
 
proc logistic data=Temp outdesign=EffectDesign(drop=FakeY) outdesignonly;
   class var / param=glm;
   model FakeY = var;
run;
 
proc print data=EffectDesign; run;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2016 02:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262268#M3863</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-08T02:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create New Variables based on Categorical Variable Value</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262270#M3864</link>
      <description>&lt;P&gt;And It is easy for IML.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
	INPUT ID VAR $;
	CARDS;
1 ONE_1
2 TWO_2
3 THREE_3
;
run;
proc iml;
use have;
read all var{var} ;
close;
col=unique(var);
x=design(var);
create want from x[r=var c=col];
append from x[r=var];
close;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Apr 2016 02:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Create-New-Variables-based-on-Categorical-Variable-Value/m-p/262270#M3864</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-08T02:48:33Z</dc:date>
    </item>
  </channel>
</rss>

