<?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 based on dates in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181166#M3635</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gergely,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for the reply, I ran the code and it worked good. But what if I have many categories for which I need to create corresponding dummies, and I don't know how many dummies there will be and what are they (and figuring this out and creating the dummies is tedious and time consuming) is there a way for SAS to do this for me instead of me actually creating dummy2010, dummy2013 etc?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Jan 2015 23:22:32 GMT</pubDate>
    <dc:creator>ilikesas</dc:creator>
    <dc:date>2015-01-13T23:22:32Z</dc:date>
    <item>
      <title>Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181161#M3630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose I have the following data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="112" style="border: 1px solid rgb(0, 0, 0); width: 156px; height: 114px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Date&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1/1/2010&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;23/6/2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;13/10/2008&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like to create are new dummy variables that will have a value of 1 for the corresponding year and 0 otherwise:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="99" style="border: 1px solid rgb(0, 0, 0); width: 610px; height: 76px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;dummy2010&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;dummy2013&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;dummy2008&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1/1/2010&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;23/6/2013&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;13/10/2008&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 21:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181161#M3630</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-13T21:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181162#M3631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;option missing=0;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; input date ddmmyy10.;&lt;BR /&gt;&amp;nbsp; format date ddmmyy10.;&lt;BR /&gt;&amp;nbsp; cards;&lt;BR /&gt;01/01/2010&lt;BR /&gt;23/06/2013&lt;BR /&gt;13/10/2008&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data temp;&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; year=year(date);&lt;BR /&gt;&amp;nbsp; N=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=temp out=want(drop=_name_) prefix=dummy;&lt;BR /&gt;&amp;nbsp; by date notsorted;&lt;BR /&gt;&amp;nbsp; id year;&lt;BR /&gt;&amp;nbsp; var N;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 21:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181162#M3631</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-13T21:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181163#M3632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi CTorres,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for replying, I ran the code and it worked fine !!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Staying on the same note, I would like to ask a small variation of my initial question please.&lt;/P&gt;&lt;P&gt;Suppose that instead of dates I had some categories and wanted to get the dummies for the categories, like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" style="border: none;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD style="border: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border: solid windowtext 1.0pt; border-left: none; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;Category&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border: solid windowtext 1.0pt; border-left: none; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;Dummy A&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border: solid windowtext 1.0pt; border-left: none; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;Dummy B&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border: solid windowtext 1.0pt; border-top: none; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;A&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="border: solid windowtext 1.0pt; border-top: none; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;B&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;0&lt;/P&gt;&lt;/TD&gt;&lt;TD style="border-top: none; border-left: none; border-bottom: solid windowtext 1.0pt; border-right: solid windowtext 1.0pt; padding: 0 5.4pt 0 5.4pt;" valign="top" width="160"&gt;&lt;P style="margin-bottom: .0001pt;"&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thank you! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 22:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181163#M3632</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-13T22:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181164#M3633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Be carefull if you set&amp;nbsp; options missing=0&amp;nbsp; .&lt;/P&gt;&lt;P&gt;Those zeros in the "want: table are still missing values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dummy2010=(year(date)=2010);&lt;/P&gt;&lt;P&gt;&amp;nbsp; dummy2013=(year(date)=2013);&lt;/P&gt;&lt;P&gt;&amp;nbsp; dummy2008=(year(date)=2008);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 23:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181164#M3633</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-01-13T23:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181165#M3634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And a similar approach on your new question:&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; dummyA=(Category='A');&lt;/P&gt;&lt;P&gt;&amp;nbsp; dummyB=(Category='B');&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 23:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181165#M3634</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-01-13T23:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181166#M3635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gergely,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for the reply, I ran the code and it worked good. But what if I have many categories for which I need to create corresponding dummies, and I don't know how many dummies there will be and what are they (and figuring this out and creating the dummies is tedious and time consuming) is there a way for SAS to do this for me instead of me actually creating dummy2010, dummy2013 etc?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 23:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181166#M3635</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-13T23:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181167#M3636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code of CTorres actually finds what dummies need to be created, but when I have the same date appearing more than once, the corresponding dummy variable isn't created because I get an error message saying that there are more than one columns of the same name...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jan 2015 23:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181167#M3636</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-13T23:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181168#M3637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's a much easier way to do this without much coding.&amp;nbsp; Let SAS create a design or model matrix usling proc logisitc and the resulting model matrix will have the form you are looking for:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*Recreate your data*/&lt;/P&gt;&lt;P&gt;data work.temp;&lt;/P&gt;&lt;P&gt;input mydate DDMMYY10.;&lt;/P&gt;&lt;P&gt;myyear=year(mydate);&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1/1/2010&lt;/P&gt;&lt;P&gt;23/6/2013&lt;/P&gt;&lt;P&gt;13/10/2008&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*This is all you need to do.&amp;nbsp; The work.xmatrix will contain your dummy coding*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; proc logistic data=work.temp outdesign=xmatrix outdesignonly;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class myyear / param=glm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model myyear=myyear;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 00:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181168#M3637</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2015-01-14T00:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181169#M3638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Statistician13,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for your code, it combines what the two previous codes separately, namely it can both automatically create the dummy variables and it allows for the same date to be repeated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the output I get an intercept value, and I guess that this is due to the proc logistic, but I can drop it right?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 00:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181169#M3638</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-14T00:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181170#M3639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure.&amp;nbsp; You can just use the drop statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; proc logistic data=work.temp outdesign=xmatrix(DROP=Intercept) outdesignonly;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; class myyear / param=glm;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; model myyear=myyear;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 00:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181170#M3639</guid>
      <dc:creator>statistician13</dc:creator>
      <dc:date>2015-01-14T00:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181171#M3640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ilikesas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hps"&gt;Although&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;irrelevant at this point&lt;/SPAN&gt;, &lt;SPAN class="hps"&gt;the variation&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;of my answer &lt;/SPAN&gt;&lt;SPAN class="hps"&gt;would be as follows: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hps"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;option missing=0;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; input id category $;&lt;BR /&gt;&amp;nbsp; N=1;&lt;BR /&gt;&amp;nbsp; cards;&lt;BR /&gt;01 A&amp;nbsp; &lt;BR /&gt;02 B&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=want(drop=_name_) prefix=dummy;&lt;BR /&gt;&amp;nbsp; by ID;&lt;BR /&gt;&amp;nbsp; id category;&lt;BR /&gt;&amp;nbsp; copy category;&lt;BR /&gt;&amp;nbsp; var N;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 14:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181171#M3640</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-14T14:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181172#M3641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi CTorres, still thank you for replying because any additional knowledge is useful!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is one problem when I use the transpose: if for example I have a date appearing several times then the transpose will give me an error because it is considering as if I want to create the same dummy column several times &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jan 2015 18:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181172#M3641</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-15T18:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181173#M3642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ilikesas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, maybe the PROC TRANSPOSE is not the rigth tool to solve your problem.&lt;/P&gt;&lt;P&gt;Anyway, you can use the &lt;STRONG&gt;LET&lt;/STRONG&gt; option to "&lt;STRONG&gt;allows duplicate values of an ID variable. PROC TRANSPOSE transposes the observation that contains the last occurrence of a particular ID value within the data set or BY group&lt;/STRONG&gt;.".&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Check the following code witch includes two additional dates: one is duplicated and the other belongs to the same year. In this case the dates must be sorted. Maybe this is what you need:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input date ddmmyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format date ddmmyy10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; year=year(date);&lt;/P&gt;&lt;P&gt;&amp;nbsp; N=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;13/10/2008&lt;/P&gt;&lt;P&gt;01/01/2010&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;01/01/2010&amp;nbsp;&amp;nbsp; &amp;lt;--- duplicated&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;23/06/2013&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;13/10/2013&amp;nbsp;&amp;nbsp; &amp;lt;--- same year&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=have out=want(drop=_name_) &lt;STRONG&gt;let&lt;/STRONG&gt; prefix=dummy;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; id year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var N;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SAS Log:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;120&amp;nbsp; data have;&lt;BR /&gt;121&amp;nbsp;&amp;nbsp;&amp;nbsp; input date ddmmyy10.;&lt;BR /&gt;122&amp;nbsp;&amp;nbsp;&amp;nbsp; format date ddmmyy10.;&lt;BR /&gt;123&amp;nbsp;&amp;nbsp;&amp;nbsp; year=year(date);&lt;BR /&gt;124&amp;nbsp;&amp;nbsp;&amp;nbsp; N=1;&lt;BR /&gt;125&amp;nbsp;&amp;nbsp;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;NOTE: The data set WORK.HAVE has 5 observations and 3 variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;NOTE: DATA statement used (Total process time):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;131&amp;nbsp; ;&lt;BR /&gt;132&amp;nbsp; run;&lt;BR /&gt;133&amp;nbsp; proc transpose data=have out=want(drop=_name_) let prefix=dummy;&lt;BR /&gt;134&amp;nbsp;&amp;nbsp;&amp;nbsp; by date;&lt;BR /&gt;135&amp;nbsp;&amp;nbsp;&amp;nbsp; id year;&lt;BR /&gt;136&amp;nbsp;&amp;nbsp;&amp;nbsp; var N;&lt;BR /&gt;137&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;WARNING: The ID value "dummy2010" occurs twice in the same BY group.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;NOTE: The above message was for the following BY group:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date=01/01/2010&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;NOTE: There were 5 observations read from the data set WORK.HAVE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;NOTE: The data set WORK.WANT has 4 observations and 4 variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;NOTE: PROCEDURE TRANSPOSE used (Total process time):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;CTorres&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Jan 2015 14:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181173#M3642</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-16T14:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181174#M3643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the result table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#000000&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;right&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;verticalAlign&amp;quot;:&amp;quot;middle&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;}" style="border: 1px solid #000000; width: 485px; height: 146px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; vertical-align: middle; background-color: #6690bc;"&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;/P&gt;&lt;/TH&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;&lt;STRONG&gt;date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;&lt;STRONG&gt;dummy2008&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;&lt;STRONG&gt;dummy2010&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;&lt;P&gt;&lt;STRONG&gt;dummy2013&lt;/STRONG&gt;&lt;/P&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;1&lt;/TH&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;13/10/2008&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;2&lt;/TH&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;01/01/2010&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;3&lt;/TH&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;23/06/2013&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TH style="padding: 2px; text-align: center; color: #ffffff; font-family: arial,helvetica,sans-serif; background-color: #6690bc;"&gt;4&lt;/TH&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;13/10/2013&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;0&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right; color: #000000; vertical-align: middle; background-color: transparent;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="text-align: left;"&gt;CTorres&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Jan 2015 15:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181174#M3643</guid>
      <dc:creator>CTorres</dc:creator>
      <dc:date>2015-01-16T15:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating dummy variables based on dates</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181175#M3644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi CTorres,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for still having an interest in the question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the code that you put above, the duplicated date was removed and as such the table has 4 observations instead of the initial 5, but the thing is that I still need the duplicated date because it corresponds to a different event, i.e, two events happened on that specific date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Jan 2015 15:44:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Creating-dummy-variables-based-on-dates/m-p/181175#M3644</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2015-01-16T15:44:33Z</dc:date>
    </item>
  </channel>
</rss>

