<?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: date format problem in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512818#M2445</link>
    <description>Your code is correct, you're just trying to apply a date format still in your format statement.</description>
    <pubDate>Wed, 14 Nov 2018 02:52:00 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-14T02:52:00Z</dc:date>
    <item>
      <title>date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512792#M2436</link>
      <description>&lt;P&gt;What am I missing to not get any results in the query?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; table1;&lt;/P&gt;
&lt;P&gt;infile datalines;&lt;/P&gt;
&lt;P&gt;input did pgm_id user $ dttime DATETIME24.3;&lt;/P&gt;
&lt;P&gt;format dttime DATETIME24.3;&lt;/P&gt;
&lt;P&gt;return;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;8 63832680 DAN 23AUG2014:19:42:55.160&lt;/P&gt;
&lt;P&gt;2 63832680 JAN 01AUG2013:19:20:58.785&lt;/P&gt;
&lt;P&gt;6 63832680 DAN 22AUG2013:13:57:12.506&lt;/P&gt;
&lt;P&gt;4 63832680 DAN 13AUG2015:19:29:39.578&lt;/P&gt;
&lt;P&gt;7 63832680 DAN 23AUG2013:15:30:00.452&lt;/P&gt;
&lt;P&gt;9 63832680 DAN 26AUG2015:20:29:40.386&lt;/P&gt;
&lt;P&gt;1 63832680 BOB 14AUG2014:22:24:41.894&lt;/P&gt;
&lt;P&gt;5 63832680 DAN 16AUG2017:18:40:52.547&lt;/P&gt;
&lt;P&gt;3 63832680 DAN 08AUG2013:19:13:00.356&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; table2 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set table1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format year_month yymmn.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format new_time date9.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_time=datepart(dttime);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year_month=new_time;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table temp7 as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from table2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where year_month = &lt;STRONG&gt;201308&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 00:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512792#M2436</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-11-14T00:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512795#M2437</link>
      <description>&lt;P&gt;So you took a DATETIME value (number of seconds) and converted it a DATE value (number of days) and stored the same value into two variables&amp;nbsp;for which you attached different display formats.&amp;nbsp; Note that both variables still have the same values, it is just how they will be displayed that is different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You then asked to find the values that where exactly 201,308, which is March 1st&amp;nbsp;in the year 2511.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to find the values that fall within a specific month then either test for the range of dates, convert the date to the first of the month and test for that date or test the output of the format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'01AUG2013'd &amp;lt;= year_month &amp;lt;= '31AUG2013'd
intnx('month',year_month,0,'b') = '01AUG2013'd
put(year_month,yymmn6.)='201308'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 00:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512795#M2437</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-14T00:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512801#M2438</link>
      <description>&lt;P&gt;i understand what you're saying. The example you give is what I have now. I wanted to simplify it to year month. I don't really need the day. How do I do that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 01:13:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512801#M2438</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-11-14T01:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512804#M2440</link>
      <description>&lt;P&gt;You shouldn't, then you lose the ability to deal with it as a date which is important when you need to determine the number of months or when it crosses years. Leaving it formatted as YYMM6 is fine, you just have to know how to specify your query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also modify your WHERE clauses to be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where year(year_month)=2018 and month(year_month) = 8&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could create two variables instead, one that's the year and one that's the month. If you want to do year over year analysis that's sometimes helpful.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 01:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512804#M2440</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-14T01:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512813#M2442</link>
      <description>&lt;P&gt;I've tried everything I can think of but I still can't get the format to a number. Here is some of what I tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; table2 ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set table1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format year_month year_month1 yymmn6.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; format new_time date9.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_time=datepart(dttime);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year_month=input(new_time,&lt;STRONG&gt;6.&lt;/STRONG&gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year_month1=input(put(new_time,yymmn6.),&lt;STRONG&gt;6.&lt;/STRONG&gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year_month2=input(put(new_time,yymmn6.),&lt;STRONG&gt;6.&lt;/STRONG&gt;);&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 02:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512813#M2442</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-11-14T02:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512816#M2444</link>
      <description>Why do you want a number?</description>
      <pubDate>Wed, 14 Nov 2018 02:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512816#M2444</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-14T02:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512818#M2445</link>
      <description>Your code is correct, you're just trying to apply a date format still in your format statement.</description>
      <pubDate>Wed, 14 Nov 2018 02:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512818#M2445</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-14T02:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512821#M2447</link>
      <description>&lt;P&gt;Because other columns in other tables in our database are in number format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Year_month2 isn't in the format statement and it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just realized that in the proc sql that follows the data step I forgot to change year_month to year_month2. It works now. Thanks a lot Reeza.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 02:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512821#M2447</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2018-11-14T02:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: date format problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512822#M2448</link>
      <description>&lt;P&gt;If you want to create a number by adding the month number to 100 times the year number then it might be clearer if you did just that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table2 ;
     set table1;
     date_only = datepart(dttime);
     year_month=100*year(date_only)+month(date_only);
     format date_only date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Nov 2018 03:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-format-problem/m-p/512822#M2448</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-14T03:05:31Z</dc:date>
    </item>
  </channel>
</rss>

