<?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: Problem with DATEPART function in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448741#M29038</link>
    <description>&lt;P&gt;You need to decide if SHP_DT has datetime values (number of seconds) or date values (number of days).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THis part of your query is treating it as if it as datetime values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;       (DATEPART(t1.shp_dt)) FORMAT=MONYY5. LABEL="MonthYr" AS MonthYr
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this part is treating it as if it as date values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; AND t1.shp_dt BETWEEN '1Jun2017'd AND '28Feb2018'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Mar 2018 17:32:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-03-26T17:32:08Z</dc:date>
    <item>
      <title>Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448636#M29024</link>
      <description>&lt;P&gt;I have two queries.&amp;nbsp; In the first query, two tables are connected:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;t1.tracking = t2.tracking&lt;/P&gt;&lt;P&gt;t1.shp_date=t2.shp_date (formatted as MMYYDDS8)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is a computed column that uses DATEPART(&lt;STRONG&gt;t1&lt;/STRONG&gt;.&lt;STRONG&gt;shp_date&lt;/STRONG&gt;) and formats as MONYY5.&amp;nbsp; I want to be able to pivot on the Month/Year for future summarizations.&amp;nbsp; The computed column result is exactly what I want.&amp;nbsp; When shp_date shows "06/01/17", my computed column shows JUN17.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the second query, I am ONLY using table t1.&amp;nbsp; I am still requesting t1.shp_date and still needing the computed column but now ALL dates are resulting in "JAN60".&amp;nbsp; I've tried everything I can think of short of connecting the other table that I do not need at this point. I would rather not do a left join on a table I don't really need.&amp;nbsp; If someone knows of a way around it, I'd appreciate your input.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI, I only use the EG GUI, no code experience.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, in advance, for your help!&lt;/P&gt;&lt;P&gt;Rita Yee&lt;/P&gt;&lt;P&gt;FedEx Express, Global Trade Services&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 14:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448636#M29024</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-03-26T14:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448639#M29026</link>
      <description>&lt;P&gt;Please post both SQL query codes. Follow the advice in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt; for posting code.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 14:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448639#M29026</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-26T14:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448640#M29027</link>
      <description>&lt;P&gt;Did you actually look at the table t1 before this second query? It sounds like you have a value of zero, and so datepart(0) will give JAN60 as the formatted result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not it, show us a representative portion of your data in t1, and show us your code.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 14:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448640#M29027</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-26T14:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448686#M29033</link>
      <description>&lt;P&gt;I guess I didn't do as good as I thought at showing that the table (t1) is exactly the same in both queries.&amp;nbsp; There are no missing dates as the results are limited by the same date range.&amp;nbsp; I just cannot fathom why the computed column works in one query and not in the other. The only difference in the two queries is that the&amp;nbsp;main table&amp;nbsp;is linked to only an imported reference table&amp;nbsp;in one query (computed doesn't work) and has an additional table joined in the&amp;nbsp;other (computed does work).&amp;nbsp; I am referencing the exact same column as the source of the computed&amp;nbsp;field&amp;nbsp;in both queries.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;COMPUTED FIELD WORKS:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.'GSP CLR WDLS Origin Country'n AS 
   SELECT DISTINCT t1.shp_dt FORMAT=MMDDYYS8. AS shp_dt, 
          t1.shp_trk_nbr, 
          /* CatCause */
            (t2.sqi_grp_ctg_cd || t2.sqi_grp_caus_cd) LABEL="CatCause" AS CatCause, 
          /* MonthYr */
            (Datepart(t1.shp_dt)) FORMAT=MONYY5. LABEL="MonthYr" AS MonthYr, 
          t1.orig_cntry_cd, 
          t2.sqi_grp_cls_cd
      FROM SCANPRST.express_volume_visibility t1, SCANPRST.exprs_vol_vsbty_esqi_enhmt t2
      WHERE (t1.shp_trk_nbr = t2.shp_trk_nbr AND t1.shp_dt = t2.shp_dt) AND (t1.orig_cntry_cd IN
           ('AF','AG','AI','AM','AN','AO','AS','AZ','BA','BD','BF','BG','BI','BJ','BN','BO','BT','BY','BZ','CD','CG',
           'CI','CK','CM','CV','CY','DJ','DM','DZ','EC','EG','ER','ET','FJ','FM','FO','GA','GE','GF','GH','GI','GL','GM'
           ,'GN','GP','GR','GY','HN','HR','HT','ID','IL','IQ','IS','IT','JO','KE','KG','KH','KZ','LA','LB','LK','LR',
           'LS','LY','MA','MD','ME','MG','MH','MK','ML','MN','MP','MR','MS','MT','MU','MV','NC','NE','NG','NI','NP','OM'
           ,'PE','PF','PG','PK','PT','PW','PY','QA','RE','RS','RU','RW','SA','SC','SK','SN','SR','SV','TD','TG','TL',
           'TN','TO','TR','TZ','UA','UG','UZ','VI','VN','VU','WF','WS','ZW') AND t2.sqi_grp_ctg_cd IN
           ('C','O','P','R','S','T','V','W','X','Y')
            AND t2.sqi_grp_caus_cd IN
           ('50','52','55','60','63','64','73','74','80','88','OV','U','UC') AND t1.shp_dt BETWEEN '1Jun2017'd AND 
           '28Feb2018'd AND t2.sqi_grp_cls_cd IN 
           (
           'W',
           'R'
           ));
QUIT;&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;&lt;STRONG&gt;COMPUTED DOESN'T WORK:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_EXPRESS_VOLUME_VISIBIL AS 
   SELECT DISTINCT t1.shp_trk_nbr, 
          t1.shp_dt FORMAT=MMDDYYS8. AS shp_dt, 
          t1.orig_cntry_cd, 
          t2.COUNTRY_NM, 
          /* MonthYr */
            (DATEPART(t1.shp_dt)) FORMAT=MONYY5. LABEL="MonthYr" AS MonthYr
      FROM SCANPRST.express_volume_visibility t1
           INNER JOIN WORK.'COUNTRY NAME TABLE'n t2 ON (t1.orig_cntry_cd = t2.COUNTRY_CD)
      WHERE t1.orig_cntry_cd IN ('AF','AG','AI','AM','AO','AS','AZ','BA','BD','BF','BG','BI','BJ','BN','BO','BT','BY',
           'BZ','CD','CG','CI','CK','CM','CV','CY','DJ','DM','DZ','EC','EG','ER','ET','FJ','FM','GA','GE','GF','GH','GI'
           ,'GM','GN','GP','GR','GY','HN','HR','HT','ID','IL','IQ','IS','IT','JO','KE','KG','KH','KZ','LA','LB','LK',
           'LR','LS','LY','MA','MD','ME','MG','MH','MK','ML','MN','MP','MR','MS','MT','MU','MV','NC','NE','NG','NI','NP'
           ,'OM','PE','PF','PG','PK','PT','PW','PY','QA','RE','RS','RU','RW','SA','SC','SK','SN','SR','SV','TG','TL',
           'TN','TO','TR','TZ','UA','UG','UZ','VI','VN','VU','WS','ZW') AND t1.shp_dt BETWEEN '1Jun2017'd AND 
           '28Feb2018'd;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Mar 2018 16:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448686#M29033</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-03-26T16:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448688#M29034</link>
      <description>&lt;P&gt;So my question "&lt;SPAN&gt;Did you actually look at the table t1 before this second query?" goes un-answered.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My request that you "show us a representative portion of your data in t1" has not been met.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 15:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448688#M29034</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-03-26T15:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448692#M29035</link>
      <description>&lt;P&gt;"So my question "&lt;SPAN&gt;Did you actually look at the table t1 before this second query?" goes un-answered.&lt;/SPAN&gt; "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;&lt;STRONG&gt;YES&amp;nbsp;&amp;nbsp; t1.shp_dt comes back with exactly the same data output&amp;nbsp;in both queries.&amp;nbsp; The computed column is what doesn't jive.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"My request that you "show us a representative portion of your data in t1" has not been met."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;&lt;STRONG&gt;No clue how to show you this.&amp;nbsp;The input table is massive.&amp;nbsp; Suggestions are appreciated.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 16:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448692#M29035</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-03-26T16:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448741#M29038</link>
      <description>&lt;P&gt;You need to decide if SHP_DT has datetime values (number of seconds) or date values (number of days).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THis part of your query is treating it as if it as datetime values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;       (DATEPART(t1.shp_dt)) FORMAT=MONYY5. LABEL="MonthYr" AS MonthYr
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And this part is treating it as if it as date values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; AND t1.shp_dt BETWEEN '1Jun2017'd AND '28Feb2018'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 17:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448741#M29038</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-26T17:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448749#M29039</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Yes, i still hate SAS &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a perfectly good example of why.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, am I to understand that DATEPART doesn't work on a Date field?&amp;nbsp; shp_dt is a date field.&amp;nbsp; In one query&amp;nbsp;DATEPART works the way I want it to.&amp;nbsp; In another query, it doesn't.&amp;nbsp; DATEPART is used&amp;nbsp;against the same column from the same source table.&amp;nbsp; I'm so damned confused, I just want to scream &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok, so let's just start over.&amp;nbsp; SHP_DT is a DATE field.&amp;nbsp; &amp;nbsp;How do I compute a column that is ONLY Month and Year, so that I can summarize monthly totals?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe I'm approaching this sideways &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 17:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448749#M29039</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-03-26T17:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448764#M29041</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/165310"&gt;@RPYee&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;Yes, i still hate SAS &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a perfectly good example of why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, am I to understand that DATEPART doesn't work on a Date field?&amp;nbsp; shp_dt is a date field.&amp;nbsp; In one query&amp;nbsp;DATEPART works the way I want it to.&amp;nbsp; In another query, it doesn't.&amp;nbsp; DATEPART is used&amp;nbsp;against the same column from the same source table.&amp;nbsp; I'm so damned confused, I just want to scream &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, so let's just start over.&amp;nbsp; SHP_DT is a DATE field.&amp;nbsp; &amp;nbsp;How do I compute a column that is ONLY Month and Year, so that I can summarize monthly totals?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe I'm approaching this sideways &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is really not hard to understand.&amp;nbsp; SAS stores dates as the number of days since 1960 and datetime as the number of seconds since 1960.&amp;nbsp; All the DATEPART() function does is divide the value by 24*60*60.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is really frustrating is working with DBMS systems that do not understand the difference between a date and a datetime (and for some do not even understand time values). So that if you want to store a date you have decide what time during that date you need to store.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 18:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448764#M29041</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-26T18:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448766#M29042</link>
      <description>&lt;P&gt;If you want to store a value that is only month and year you could convert it to a character string. (date step syntax)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;yymm = put(date,yymmn6.);
monyy = put(date,monyy7.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could apply a format that displays it as just the month and year.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format mydate yymmn6. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could convert the value to a consistent day with in that month and apply the format. For example the first day of the month. (sql syntax)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx('month',date,0,'b') as monyy format=monyy7.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mdy(month(date),1,year(date)) as monyy format=monyy7.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Mar 2018 22:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/448766#M29042</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-26T22:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with DATEPART function</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/452859#M29218</link>
      <description>Changed column to the datetime column instead of just the date column. It's weird that it let me use DATEPART on the date column in another query... Oh well. It's working now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks, Tom!! I appreciate your help and patience with me.</description>
      <pubDate>Tue, 10 Apr 2018 15:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Problem-with-DATEPART-function/m-p/452859#M29218</guid>
      <dc:creator>RPYee</dc:creator>
      <dc:date>2018-04-10T15:09:36Z</dc:date>
    </item>
  </channel>
</rss>

