<?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 Creating dummy variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/789749#M252761</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for an efficient way to create dummy variables and I've seen this example online:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;DATA auto ;
  LENGTH make $ 20 ;
  INPUT make $ 1-17 price mpg rep78 ;
CARDS;
AMC Concord        4099 22 3 
AMC Pacer          4749 17 3 
Audi 5000          9690 17 5 
Audi Fox           6295 23 3 
BMW 320i           9735 25 4 
Buick Century      4816 20 3 
Buick Electra      7827 15 4 
Buick LeSabre      5788 18 3 
Cad. Eldorado     14500 14 2 
Olds Starfire      4195 24 1 
Olds Toronado     10371 16 3 
Plym. Volare       4060 18 2 
Pont. Catalina     5798 18 4 
Pont. Firebird     4934 18 1 
Pont. Grand Prix   5222 19 3 
Pont. Le Mans      4723 19 3 
;
RUN;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;DATA auto2;
  set auto;
 
  ARRAY dummys {*} 3.  rep78_1 - rep78_5;
 
  DO i=1 TO 5;			      
    dummys(i) = 0;
  END;
  dummys( rep78  ) = 1;		
 
RUN;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;This has been working for me except when I have missing values (e.g. if rep78 has missing values). Is there a way to adjust this code to account for the missing values or do I need a different solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2022 15:38:13 GMT</pubDate>
    <dc:creator>mt88</dc:creator>
    <dc:date>2022-01-12T15:38:13Z</dc:date>
    <item>
      <title>Creating dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/789749#M252761</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for an efficient way to create dummy variables and I've seen this example online:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;DATA auto ;
  LENGTH make $ 20 ;
  INPUT make $ 1-17 price mpg rep78 ;
CARDS;
AMC Concord        4099 22 3 
AMC Pacer          4749 17 3 
Audi 5000          9690 17 5 
Audi Fox           6295 23 3 
BMW 320i           9735 25 4 
Buick Century      4816 20 3 
Buick Electra      7827 15 4 
Buick LeSabre      5788 18 3 
Cad. Eldorado     14500 14 2 
Olds Starfire      4195 24 1 
Olds Toronado     10371 16 3 
Plym. Volare       4060 18 2 
Pont. Catalina     5798 18 4 
Pont. Firebird     4934 18 1 
Pont. Grand Prix   5222 19 3 
Pont. Le Mans      4723 19 3 
;
RUN;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;DATA auto2;
  set auto;
 
  ARRAY dummys {*} 3.  rep78_1 - rep78_5;
 
  DO i=1 TO 5;			      
    dummys(i) = 0;
  END;
  dummys( rep78  ) = 1;		
 
RUN;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;This has been working for me except when I have missing values (e.g. if rep78 has missing values). Is there a way to adjust this code to account for the missing values or do I need a different solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 15:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/789749#M252761</guid>
      <dc:creator>mt88</dc:creator>
      <dc:date>2022-01-12T15:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/789750#M252762</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA auto2;
  set auto;
  ARRAY dummys rep78_1 - rep78_5 (5*0);
  if not missing(rep78) then dummys( rep78 ) = 1;		
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives your dummy variables a value of zero when rep78 is missing. You can modify that further to give the dummy variables a missing value as well.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 17:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/789750#M252762</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-12T17:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/836176#M330636</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You mentioned that 'You can modify that further to give the dummy variables a missing value as well.' Can you show me that modification?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 17:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/836176#M330636</guid>
      <dc:creator>mt88</dc:creator>
      <dc:date>2022-09-30T17:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/836180#M330639</link>
      <description>&lt;P&gt;Replace the 0 with a .&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2022 17:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/836180#M330639</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-30T17:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/836228#M330654</link>
      <description>&lt;P&gt;Make sure the value of REP78 is something you could use as an index into the array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if rep78  in (1:5) then  dummys( rep78  ) = 1;	&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Sep 2022 21:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-dummy-variables/m-p/836228#M330654</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-30T21:42:43Z</dc:date>
    </item>
  </channel>
</rss>

