<?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 multiple dummy variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740398#M231281</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set have;
length name $4;
value = 1;
do i = 1 to length(code) by 4;
  name = substr(code,i,4);
  output;
end;
keep id name value;
run;

proc transpose 
  data=long
  out=want
;
by id;
var value;
id name;
run;

/* alternatively */
proc report data=long;
column id name;
define id / group;
define name / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 07:37:38 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-05-11T07:37:38Z</dc:date>
    <item>
      <title>create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740389#M231280</link>
      <description>&lt;P&gt;I want to create a dummy variable column for every code. This normally wouldn't be hard but because I am looking for substrings in a string it has stumped me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current data set:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Code&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1280&lt;/TD&gt;&lt;TD&gt;A001B007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2125&lt;/TD&gt;&lt;TD&gt;A001B007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2170&lt;/TD&gt;&lt;T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/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 07:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740389#M231280</guid>
      <dc:creator>sasprogramming</dc:creator>
      <dc:date>2021-05-11T07:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740398#M231281</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set have;
length name $4;
value = 1;
do i = 1 to length(code) by 4;
  name = substr(code,i,4);
  output;
end;
keep id name value;
run;

proc transpose 
  data=long
  out=want
;
by id;
var value;
id name;
run;

/* alternatively */
proc report data=long;
column id name;
define id / group;
define name / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 07:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740398#M231281</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-11T07:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740435#M231298</link>
      <description>&lt;P&gt;This doesn't work unofortunately&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 11:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740435#M231298</guid>
      <dc:creator>sasprogramming</dc:creator>
      <dc:date>2021-05-11T11:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740449#M231302</link>
      <description>&lt;P&gt;"Doesn't work" on its own is not helpful. Please invest some effort into your answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you mean that you want zeroes instead of missing values, you need a standardization step after the transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose 
  data=long
  out=pre_want;
;
by id;
var value;
id name;
run;

proc stdize
  data=pre_want
  out=want (drop=_name_)
  missing=0
  reponly
;
var _numeric_;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;ID	A001	B007	B002	C023
1280	1	1	0	0
2125	1	1	0	0
2170	0	0	1	0
2413	1	0	0	1
2440	0	0	0	1&lt;/PRE&gt;
&lt;P&gt;or, for the PROC REPORT, add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(same result)&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 13:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740449#M231302</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-11T13:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740662#M231409</link>
      <description>The code is working almost fine, what I end up with is the following:&lt;BR /&gt;&lt;BR /&gt;ID	name	value&lt;BR /&gt;1280	A001	1&lt;BR /&gt;1280	B007	1&lt;BR /&gt;2125	A001	1&lt;BR /&gt;2170	B007	1&lt;BR /&gt;2413	A001	1&lt;BR /&gt;2413	C023	1&lt;BR /&gt;2440	C023	1&lt;BR /&gt;</description>
      <pubDate>Wed, 12 May 2021 00:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740662#M231409</guid>
      <dc:creator>sasprogramming</dc:creator>
      <dc:date>2021-05-12T00:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740720#M231433</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302184"&gt;@sasprogramming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The code is working almost fine, what I end up with is the following:&lt;BR /&gt;&lt;BR /&gt;ID name value&lt;BR /&gt;1280 A001 1&lt;BR /&gt;1280 B007 1&lt;BR /&gt;2125 A001 1&lt;BR /&gt;2170 B007 1&lt;BR /&gt;2413 A001 1&lt;BR /&gt;2413 C023 1&lt;BR /&gt;2440 C023 1&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Seems that something is wrong in the code you actually submitted. Please share the code using "Insert SAS Code" button.&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 05:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/740720#M231433</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-05-12T05:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple dummy variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/741058#M231621</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302184"&gt;@sasprogramming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The code is working almost fine, what I end up with is the following:&lt;BR /&gt;&lt;BR /&gt;ID name value&lt;BR /&gt;1280 A001 1&lt;BR /&gt;1280 B007 1&lt;BR /&gt;2125 A001 1&lt;BR /&gt;2170 B007 1&lt;BR /&gt;2413 A001 1&lt;BR /&gt;2413 C023 1&lt;BR /&gt;2440 C023 1&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's the "long" dataset; from this you run TRANSPOSE and STDIZE, or PROC REPORT with OPTIONS MISSING=0.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 May 2021 11:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-dummy-variables/m-p/741058#M231621</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-13T11:13:31Z</dc:date>
    </item>
  </channel>
</rss>

