<?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: Grouping dates and creating dummy variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704014#M26089</link>
    <description>&lt;P&gt;For chi-squared test and logistic regression, you do not have to create your own dummy variables. If your professor is telling you that you have to, then your professor is wrong, you don't have to create dummy variables for this problem, and there are much more efficient ways of doing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable EVENTDATE is numeric and formatted as mmddyy (I'm still a little skeptical, I did ask you to show me a typical value of EVENTDATE, &lt;FONT color="#FF0000"&gt;so please show me a typical value of EVENTDATE&lt;/FONT&gt;) then this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    month_variable=month(eventdate);
run;

proc logistic data=want;
    class month_variable;
    model y = month_variable;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No user-created dummy variables needed. SAS creates the dummy variables behind the scenes, so you don't have to. That's what the CLASS statement does.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Dec 2020 01:47:55 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-12-07T01:47:55Z</dc:date>
    <item>
      <title>Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704009#M26085</link>
      <description>&lt;DIV&gt;I am working on a code to group date ranges and create a dummy variable and I am stuck trying to figure out why SAS is not picking up on the code. I would like to know if I am heading in the right direction.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;DATA work.import;&lt;BR /&gt;SET work.import;&lt;BR /&gt;IF (eventdate &amp;gt;= "03012020") and (eventdate &amp;lt;= "03312020") then month = 3;&lt;BR /&gt;IF (eventdate &amp;gt;= "04012020") AND (eventdate &amp;lt;= "04302020") then month = 4;&lt;BR /&gt;IF (eventdate &amp;gt;= "05012020") and (eventdate &amp;lt;= "05312020") then month = 5;&lt;BR /&gt;if (eventdate &amp;gt;= "06012020") and (eventdate &amp;lt;= "06302020") then month=6;&lt;BR /&gt;if (eventdate &amp;gt;= "07012020") and (eventdate &amp;lt;= "07312020") then month=7;&lt;BR /&gt;if (eventdate =&amp;gt; "08012020") and (eventdate &amp;lt;= "08312020") then month=8;&lt;BR /&gt;if (eventdate =&amp;gt; "09012020") and (eventdate &amp;lt;= "09302020") then month=9;&lt;BR /&gt;if (eventdate =&amp;gt; "10012020") and (eventdate &amp;lt;= "10312020") then month=10;&lt;BR /&gt;if (eventdate =&amp;gt; "11012020") and (eventdate &amp;lt;= "11302020") then month=11;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704009#M26085</guid>
      <dc:creator>Lilo</dc:creator>
      <dc:date>2020-12-07T01:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704010#M26086</link>
      <description>&lt;P&gt;Rarely would you ever need to create your own DUMMY variables in SAS. There are many more efficient ways to do this, SAS has done the hard work here so you don't have to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before I can provide code that helps, please answer some questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are typical values of the variable eventdate?&lt;/P&gt;
&lt;P&gt;Is eventdate numeric or character, according to PROC CONTENTS?&lt;/P&gt;
&lt;P&gt;What analysis are you going to do with these dummy variables once you have them?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704010#M26086</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-07T01:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704012#M26088</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;To answer your questions: I did run a proc contents and the event dates are numerical and in this format: mmddyy. Also, once I have the data, I will be running a chi-square and logistic regression analysis. My professor is asking to create a "dummy" variables for months: March through November.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704012#M26088</guid>
      <dc:creator>Lilo</dc:creator>
      <dc:date>2020-12-07T01:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704014#M26089</link>
      <description>&lt;P&gt;For chi-squared test and logistic regression, you do not have to create your own dummy variables. If your professor is telling you that you have to, then your professor is wrong, you don't have to create dummy variables for this problem, and there are much more efficient ways of doing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable EVENTDATE is numeric and formatted as mmddyy (I'm still a little skeptical, I did ask you to show me a typical value of EVENTDATE, &lt;FONT color="#FF0000"&gt;so please show me a typical value of EVENTDATE&lt;/FONT&gt;) then this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    month_variable=month(eventdate);
run;

proc logistic data=want;
    class month_variable;
    model y = month_variable;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No user-created dummy variables needed. SAS creates the dummy variables behind the scenes, so you don't have to. That's what the CLASS statement does.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704014#M26089</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-07T01:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704017#M26090</link>
      <description>&lt;P&gt;Eventdate is given in this format:&amp;nbsp;&lt;SPAN&gt;08/27/2020&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:55:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704017#M26090</guid>
      <dc:creator>Lilo</dc:creator>
      <dc:date>2020-12-07T01:55:47Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704018#M26091</link>
      <description>&lt;P&gt;Then the code I gave should work.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704018#M26091</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-07T01:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704019#M26092</link>
      <description>&lt;P&gt;Thank you so much...I really appreciate it!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 01:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704019#M26092</guid>
      <dc:creator>Lilo</dc:creator>
      <dc:date>2020-12-07T01:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704192#M26099</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/359878"&gt;@Lilo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;To answer your questions: I did run a proc contents and the event dates are numerical and in this format: mmddyy. Also, once I have the data, I will be running a chi-square and logistic regression analysis. My professor is asking to create a "dummy" variables for months: March through November.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So if your data is numeric why did you write a bunch of comparisons of Character values such as &lt;/P&gt;
&lt;PRE&gt;IF (eventdate &amp;gt;= "03012020")&lt;/PRE&gt;
&lt;P&gt;The information you show indicates the values are being treated as dates, which is correct.&lt;/P&gt;
&lt;P&gt;You can create groups by applying desired date format to your variable to create groups honored by reporting, analysis and most graphing processes.&lt;/P&gt;
&lt;P&gt;Changing the format to YYmmn. will group the data by year and month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this code and see:&lt;/P&gt;
&lt;PRE&gt;Proc freq data=work.import;
   tables eventdate;
   format eventdate yymmn.;
run;&lt;/PRE&gt;
&lt;P&gt;Seldom a good idea to separate year from month unless you really know what you are doing with the dates. Or you could use the MONTH format to display just the number of the month, or MONNAME format display the month of the year. The concept of Format is very important in SAS as it allows changing displayed values without changing the underlying value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For beginning SAS users it is a poor idea to use code like:&lt;/P&gt;
&lt;PRE&gt;data somedatasetname;
    set somedatasetname;
&amp;lt;other code&amp;gt;&lt;/PRE&gt;
&lt;P&gt;If you do not have a serious error that will replace the existing Somedatasetname data set completely. Which means that you may accidentally replace starting values and have to go back to your original data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 16:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704192#M26099</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-07T16:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping dates and creating dummy variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704202#M26101</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Seldom a good idea to separate year from month unless you really know what you are doing with the dates. &lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I agree. I get the impression this idea of using months March through November, without a year, comes from the professor, which may be fine for this specific problem, but it's poor logic in general.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, shockingly, the professor wants dummy variables to be used here, which is completely unnecessary, and it seems as if the professor is leading the students down a sub-optimal path.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 16:49:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Grouping-dates-and-creating-dummy-variables/m-p/704202#M26101</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-07T16:49:08Z</dc:date>
    </item>
  </channel>
</rss>

