<?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 Dummy Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959649#M374406</link>
    <description>&lt;P&gt;white = (missing(race) or (race=1))*1;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Feb 2025 18:27:59 GMT</pubDate>
    <dc:creator>subhashmantha</dc:creator>
    <dc:date>2025-02-19T18:27:59Z</dc:date>
    <item>
      <title>Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959615#M374392</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;I was wondering how to create dummy variables with "white" being the baseline. I have 5 categories (American Indian, White, Black, Pacific Islanders, Asian).&lt;/P&gt;&lt;P&gt;The variable race is coded (0=Black, 1=White,2=American Indian,3=Asian,4=Native Hawaiian).&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;if race=0 then Black=1;&lt;BR /&gt;else Black=0;&lt;BR /&gt;if race=2 then AmericanIndian=1;&lt;BR /&gt;else AmericanIndian=0;&lt;BR /&gt;if race=3 then Asian=1;&lt;BR /&gt;else Asian=0;&lt;BR /&gt;if race=4 then Pacific_Islander=1;&lt;BR /&gt;else Pacific_Islander=0;&lt;BR /&gt;where White is currently the baseline. However, the variable race have missing data and I'm assuming those missing data are given a value of zero too.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 15:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959615#M374392</guid>
      <dc:creator>Reader587</dc:creator>
      <dc:date>2025-02-19T15:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959619#M374395</link>
      <description>&lt;P&gt;There are procedures like TRANSREG and GLMMOD that will code for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to code yourself, recognize that the result of a Boolean (logical) expression is 1 if true and 0 if false. So each IF/ELSE pair could be replaced by a simple assignment statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Black = (Race = 0);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The parens are not required, but you might want them for clarity.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 15:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959619#M374395</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2025-02-19T15:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959622#M374396</link>
      <description>&lt;P&gt;data abc;&lt;/P&gt;&lt;P&gt;set abc;&lt;/P&gt;&lt;P&gt;Black = (race=0)*1;&lt;/P&gt;&lt;P&gt;White = (race=1)*1;&lt;/P&gt;&lt;P&gt;AmericanIndian = (race=2)*1;&lt;/P&gt;&lt;P&gt;Asian = (race=3)*1;&lt;/P&gt;&lt;P&gt;NativeHawaiian = (race=4)*1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 15:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959622#M374396</guid>
      <dc:creator>subhashmantha</dc:creator>
      <dc:date>2025-02-19T15:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959623#M374397</link>
      <description>&lt;P&gt;For a good article on using a SAS procedure, see this topic from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/08/31/best-generate-dummy-variables-sas.html" target="_self"&gt;The best way to generate dummy variables in SAS&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 16:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959623#M374397</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2025-02-19T16:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959627#M374399</link>
      <description>But "White" is not the baseline here.</description>
      <pubDate>Wed, 19 Feb 2025 16:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959627#M374399</guid>
      <dc:creator>Reader587</dc:creator>
      <dc:date>2025-02-19T16:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959630#M374400</link>
      <description>&lt;P&gt;Why do you need dummy variables at all? Almost every SAS modeling procedure creates the dummy variables for you behind the scenes so you don't have to, avoiding all of these pitfalls and potential errors. And you can specify which level is the reference (or baseline) level. This is one of the great advantages of using SAS for modeling.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 16:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959630#M374400</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-19T16:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959632#M374401</link>
      <description>Thanks. How do I get "White" to be the baseline with missing data? Since it appears "White" and "Missing" would both be coded zero if I code everything else 1.</description>
      <pubDate>Wed, 19 Feb 2025 16:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959632#M374401</guid>
      <dc:creator>Reader587</dc:creator>
      <dc:date>2025-02-19T16:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959634#M374402</link>
      <description>&lt;P&gt;I think you might need an "unknown" category in that case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Unknown = missing(race);&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2025 17:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959634#M374402</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2025-02-19T17:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959647#M374404</link>
      <description>&lt;P&gt;PROC TRANSREG and also be useful here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*0=Black, 1=White,2=American Indian,3=Asian,4=Native Hawaiian). */
data race;
   do race = 0,.,1 to 4;
      output;
      end;
   run;
proc transreg data=race;
   model class(race/zero='1');
   id race;
   output out=design(drop=intercept) design;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 519px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104747iAA6436C9F1C7C40B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps this one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*0=Black, 1=White,2=American Indian,3=Asian,4=Native Hawaiian). */
data race;
   do race = 0,.,1 to 4;
      output;
      end;
   run;
proc transreg data=race;
   model class(race/dev zero='1');
   id race;
   output out=design(drop=intercept) design;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 513px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104748i17FCE17BAB2909F1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 18:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959647#M374404</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-02-19T18:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959649#M374406</link>
      <description>&lt;P&gt;white = (missing(race) or (race=1))*1;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 18:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959649#M374406</guid>
      <dc:creator>subhashmantha</dc:creator>
      <dc:date>2025-02-19T18:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959652#M374407</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/217081"&gt;@subhashmantha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;white = (missing(race) or (race=1))*1;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or don't even try to create the dummy variables yourself, SAS can create them for you from your data by using the CLASS statement in a modeling procedure, so you don't have to create the dummy variables.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2025 18:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959652#M374407</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-19T18:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959746#M374433</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/217081"&gt;@subhashmantha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;white = (missing(race) or (race=1))*1;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or don't even try to create the dummy variables yourself, SAS can create them for you from your data by using the CLASS statement in a modeling procedure, so you don't have to create the dummy variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't a missing value for a class variable like Race either remove the observation or with the MISSING option treat it as a different level than Race=1? Perhaps this special case of the missing value could be use of the MISSING option plus a custom format to have missing and 1 treated as a single class?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 05:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959746#M374433</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-02-20T05:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959768#M374437</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Custom format or custom informat, and then stop writing your own DUMMY variables and use SAS PROCs to compute the dummy variables behind the scenes.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Feb 2025 11:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Dummy-Variables/m-p/959768#M374437</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-20T11:18:19Z</dc:date>
    </item>
  </channel>
</rss>

