<?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: How do I create this table using proc sql passthru using teradata  calendar table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604773#M175370</link>
    <description>&lt;P&gt;Change your WHERE clause logic so that you select more than one row from the source table.&lt;/P&gt;
&lt;PRE&gt;WHERE 
  calendar_date &amp;gt;= DATE '2008-12-29' 
  and calendar_date &amp;lt;= DATE '2021-12-27'&lt;/PRE&gt;</description>
    <pubDate>Sun, 17 Nov 2019 04:19:23 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-11-17T04:19:23Z</dc:date>
    <item>
      <title>How do I create this table using proc sql passthru using teradata  calendar table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604768#M175366</link>
      <description>&lt;P&gt;This is more of a teradata question since I am using proc sql passthru to generate the table below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like 12-29-2008 to be the start date for my table i.e. I want to assign this as the start date and with the week number corresponding to this as 209 (in a different column).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then the next row follows with the following Monday (+7 days)&amp;nbsp; and the week number corresponding to this is being incremented by 1 (i.e.209+1) . The end date for this table is 12/27/2021 (Monday)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TABLE STRUCTURE is below:&lt;/P&gt;&lt;P&gt;Weekstart/Monday of the week&amp;nbsp; &amp;nbsp; Week num&lt;/P&gt;&lt;P&gt;12/29/2008&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 209&lt;/P&gt;&lt;P&gt;1/5/2009&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;210&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;12/27/2021&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;887&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="post-text"&gt;&lt;P&gt;I tried something like below but it only generated one row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SEL WeekBegin , (WeekBegin - DATE '2008-12-29')/7 + 209 as week_num&lt;/P&gt;&lt;P&gt;FROM Sys_Calendar.BusinessCalendar&lt;/P&gt;&lt;P&gt;WHERE calendar_date = DATE '2008-12-29';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please let me know how we can do an autocalculate using the syscalendar in teradata and obtain the subsequent rows i.e. the entire table all the way through 12/27/21 ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help on this!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="post-taglist grid gs4 gsy fd-column"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Sun, 17 Nov 2019 02:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604768#M175366</guid>
      <dc:creator>ilearnsas</dc:creator>
      <dc:date>2019-11-17T02:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create this table using proc sql passthru using teradata  calendar table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604773#M175370</link>
      <description>&lt;P&gt;Change your WHERE clause logic so that you select more than one row from the source table.&lt;/P&gt;
&lt;PRE&gt;WHERE 
  calendar_date &amp;gt;= DATE '2008-12-29' 
  and calendar_date &amp;lt;= DATE '2021-12-27'&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Nov 2019 04:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604773#M175370</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-17T04:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create this table using proc sql passthru using teradata  calendar table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604789#M175376</link>
      <description>&lt;P&gt;Thanks. I tried below.&lt;/P&gt;&lt;PRE&gt;    &lt;SPAN&gt;SEL&lt;/SPAN&gt; &lt;SPAN&gt;WeekBegin&lt;/SPAN&gt;&lt;SPAN&gt;, (&lt;/SPAN&gt;&lt;SPAN&gt;WeekBegin&lt;/SPAN&gt; &lt;SPAN&gt;-&lt;/SPAN&gt; &lt;SPAN&gt;DATE&lt;/SPAN&gt; &lt;SPAN&gt;'2008-12-29'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt;7&lt;/SPAN&gt; &lt;SPAN&gt;+&lt;/SPAN&gt; &lt;SPAN&gt;209&lt;/SPAN&gt; &lt;SPAN&gt;as&lt;/SPAN&gt; &lt;SPAN&gt;week_num&lt;/SPAN&gt;
&lt;SPAN&gt;FROM&lt;/SPAN&gt; &lt;SPAN&gt;Sys_Calendar&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;BusinessCalendar&lt;/SPAN&gt; 
    &lt;SPAN&gt;WHERE&lt;/SPAN&gt; 
  &lt;SPAN&gt;calendar_date&lt;/SPAN&gt; &lt;SPAN&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN&gt;DATE&lt;/SPAN&gt; &lt;SPAN&gt;'2008-12-29'&lt;/SPAN&gt; 
  &lt;SPAN&gt;and&lt;/SPAN&gt; &lt;SPAN&gt;calendar_date&lt;/SPAN&gt; &lt;SPAN&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN&gt;DATE&lt;/SPAN&gt; &lt;SPAN&gt;'2021-12-27'&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;It gives 3 rows and 3 weeknum for the same date.&lt;BR /&gt;&lt;BR /&gt;The output looked like below:&lt;BR /&gt;&lt;BR /&gt;Weekbegin      Weeknum&lt;BR /&gt;12/28/2008      209&lt;BR /&gt;12/28/2008      209&lt;BR /&gt;12/28/2008       209&lt;BR /&gt;...&lt;BR /&gt;12/26/2021       886&lt;BR /&gt;12/26/2021       886&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The errors are below-&lt;BR /&gt;1. See duplicate entires (3 rows or 2 rows instead of 1)&lt;BR /&gt;2. Need to display monday of the week (however the last row displayed was 12/26/21 instead of 12/27/21 -- and the &lt;BR /&gt;corresponding week num should be 887 and not 886. Any suggestion on how we can fix this to get Monday of every week&lt;BR /&gt;until 12/27/21?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How do we get one unique row for each date and weeknum (no dups) and also get only Monday of every week?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 13:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604789#M175376</guid>
      <dc:creator>ilearnsas</dc:creator>
      <dc:date>2019-11-17T13:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create this table using proc sql passthru using teradata  calendar table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604842#M175404</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;I don't know why you're getting multiple rows for the query you've posted.&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;Updated post:&lt;/P&gt;
&lt;P&gt;You're just selecting rows from a single "table" so there can't be any duplication of rows but it must already be this way in the source table. Your source table has a row per date so that's 7 rows per week - and that's what you get with your query.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just need to de-dup the result then you can use DISTINCT in your Select statement or follow what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;suggests.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 03:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604842#M175404</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-18T03:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create this table using proc sql passthru using teradata  calendar table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604850#M175408</link>
      <description>&lt;P&gt;If you select by WEEKBEGIN you are going to get 7 observations since there are 7 days in a week.&lt;/P&gt;
&lt;P&gt;If you want to select by MONDAY then use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;day_of_week=2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since that variable is code 1 to 7 with 1 meaning Sunday.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Nov 2019 22:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-this-table-using-proc-sql-passthru-using/m-p/604850#M175408</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-17T22:19:40Z</dc:date>
    </item>
  </channel>
</rss>

