<?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 Variable in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599515#M29142</link>
    <description>&lt;P&gt;First of all, you can't convert a character variable to a numeric one on the fly. You need to create a new variable.&lt;/P&gt;
&lt;P&gt;Several methods can be used.&lt;/P&gt;
&lt;P&gt;With an informat&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
informat insex
  "female" = 0
  "male" = 1
;
run;

data want;
set have;
sex_num = input(sex,insex.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or by using a condition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if sex = "female"
then sex_num = 0;
else sex_num = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or the same, using a function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_sex);
set have (rename=(sex=_sex));
sex = ifn(_sex = "female",0,1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the last one, you can see how to completely replace the variable by using dataset options.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Oct 2019 07:32:48 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-10-26T07:32:48Z</dc:date>
    <item>
      <title>Creating Dummy Variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599509#M29141</link>
      <description>&lt;P&gt;Hi, I have been trying for hours (in SAS University Version) to re-code SEX by a dummy variable Z (female: Z = 0 and male: Z = 1), such as IF SEX=’female’ THEN Z=0;&lt;BR /&gt;ELSE Z=1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output results in blank spaces. I can't figure it out. Here is the data if someone could help me, please. Thank you so much!&lt;/P&gt;&lt;PRE&gt;YEAR	X	SEX	COLLEGE&lt;BR /&gt;1975	1	female	4.4&lt;BR /&gt;1976	2	female	4.7&lt;BR /&gt;1977	3	female	4.8&lt;BR /&gt;1978	4	female	4.7&lt;BR /&gt;1979	5	female	5&lt;BR /&gt;1980	6	female	6&lt;BR /&gt;1981	7	female	6.2&lt;BR /&gt;1982	8	female	6.4&lt;BR /&gt;1983	9	female	6.3&lt;BR /&gt;1984	10	female	6.3&lt;BR /&gt;1985	11	female	6.6&lt;BR /&gt;1986	12	female	6.6&lt;BR /&gt;1987	13	female	6.7&lt;BR /&gt;1988	14	female	7.2&lt;BR /&gt;1989	15	female	7.2&lt;BR /&gt;1990	16	female	7.4&lt;BR /&gt;1991	17	female	7.6&lt;BR /&gt;1992	18	female	7.8&lt;BR /&gt;1993	19	female	7.6&lt;BR /&gt;1975	1	male	5.3&lt;BR /&gt;1976	2	male	5.3&lt;BR /&gt;1977	3	male	5.4&lt;BR /&gt;1978	4	male	5.1&lt;BR /&gt;1979	5	male	5&lt;BR /&gt;1980	6	male	5.4&lt;BR /&gt;1981	7	male	5.6&lt;BR /&gt;1982	8	male	5.9&lt;BR /&gt;1983	9	male	6&lt;BR /&gt;1984	10	male	6&lt;BR /&gt;1985	11	male	5.9&lt;BR /&gt;1986	12	male	5.8&lt;BR /&gt;1987	13	male	6&lt;BR /&gt;1988	14	male	5.9&lt;BR /&gt;1989	15	male	6&lt;BR /&gt;1990	16	male	6.2&lt;BR /&gt;1991	17	male	6.4&lt;BR /&gt;1992	18	male	6.2&lt;BR /&gt;1993	19	male	6.3&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 04:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599509#M29141</guid>
      <dc:creator>Joa14</dc:creator>
      <dc:date>2019-10-26T04:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599515#M29142</link>
      <description>&lt;P&gt;First of all, you can't convert a character variable to a numeric one on the fly. You need to create a new variable.&lt;/P&gt;
&lt;P&gt;Several methods can be used.&lt;/P&gt;
&lt;P&gt;With an informat&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
informat insex
  "female" = 0
  "male" = 1
;
run;

data want;
set have;
sex_num = input(sex,insex.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or by using a condition&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if sex = "female"
then sex_num = 0;
else sex_num = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or the same, using a function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_sex);
set have (rename=(sex=_sex));
sex = ifn(_sex = "female",0,1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the last one, you can see how to completely replace the variable by using dataset options.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 07:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599515#M29142</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-26T07:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599516#M29143</link>
      <description>&lt;P&gt;PS it is essential to know the current status. SEX might already be numeric and have a format attached, or the contents might not be exactly what you see (leading blanks etc, ). Also consider that the condition will be case-sensitive ("Female" &amp;lt;&amp;gt; "female"!).&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 10:37:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599516#M29143</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-26T10:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599520#M29144</link>
      <description>&lt;P&gt;It is rare when you need to covert categorical variables to dummy variables. Most SAS procedures work fine with the values 'female' and 'male', and don't need dummy variables; in fact they create the dummy variables internally so &lt;STRONG&gt;you don't have to&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, unless you are in one of those very rare situations where you actually need to have dummy variables (and nothing you have said indicates you are in one of those very rare situations), don't create your own dummy variables. Make your life simple, do it the easy way.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 11:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599520#M29144</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-26T11:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599539#M29149</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Paige Miller thank you so much. I agree with you, unfortunately, I have been requested to convert it by dummy variable.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Joa14&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 16:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599539#M29149</guid>
      <dc:creator>Joa14</dc:creator>
      <dc:date>2019-10-26T16:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Dummy Variable</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599540#M29150</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;&lt;SPAN class="login-bold"&gt;KurtBremser&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your response. The second code you gave me is very similar to the one I was using. The only difference is that I was using 'female' instead of "female" I do not know why it turned out to be a big difference. I got the dummy variable with that change. Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joa14&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 16:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Creating-Dummy-Variable/m-p/599540#M29150</guid>
      <dc:creator>Joa14</dc:creator>
      <dc:date>2019-10-26T16:05:06Z</dc:date>
    </item>
  </channel>
</rss>

