<?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: SAS/access to Teradata  create  multiple derived tables in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/404071#M25937</link>
    <description>&lt;P&gt;Your TD code does not look like valid code.&amp;nbsp; Can you run that code on your TD server using Teradata SQL assistant?&lt;/P&gt;
&lt;P&gt;IN general an SQL query should be of the form&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select ....
from ...
where ...
group by ....
having ....
order by ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where just the SELECT and FROM clauses are required.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Oct 2017 18:42:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-10-13T18:42:39Z</dc:date>
    <item>
      <title>SAS/access to Teradata  create  multiple derived tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403753#M25905</link>
      <description>&lt;P&gt;I need to create a matrix type calendar query that will replace rows that have zero value with 2 as the value in the summary column. This query is based&amp;nbsp;on a file that runs monthly and daily. The file doesn't run on weekends or holidays.&amp;nbsp; In my&amp;nbsp;query, The&amp;nbsp;&lt;SPAN&gt;max_month&lt;/SPAN&gt; column values are compared with the summary column values. If there are&amp;nbsp;missing months in the summary column than the missing values&amp;nbsp;are replaced with zeros. The last step is to output the data set to a text file.&amp;nbsp; My query isn't&amp;nbsp; outputting any results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the&amp;nbsp;attachment, there is a text file name&amp;nbsp;tran_sumary and an&amp;nbsp;excel file name month.xls.&amp;nbsp; The tran_sumary file is a data file and month.xls is an example of what my query results need to print&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;create table xxx as 
select  * from connection to teradata
   (SELECT
       FROM
       b.LD_T,
       b.K_KY

/* create derived table b  and select the columns– extracts K_KY dates in the format of example SEP and print the K_KY largest count - b(&amp;lt;column list&amp;gt;)*/

    (select
       b.LD_T,
       b.K_KY
        cast(cast( b.K_KY as char(3)) as date format 'MMM')  AS MAX_MNTH,
        cast(cast(b.K_KY as char(8)) as date format 'yyyymmdd')  AS tran_dt
        from dy b
        Group BY 1,2
         Having Count(*) &amp;gt;1;)  AS b(LD_T,  MAX_MNTH, tran_dt)

/* create derived table c and select the columns – extracts sumary_end-dt dates in the format for example SEP and print the sumary_end-dt largest  count b(&amp;lt;column list&amp;gt;)*/ */

       (SELECT
          FROM
            c.sumary_end_dt
        ( SELECT
            c.sumary_end_dt
             cast(cast( a.sumary_end_dt as char(3)) as date format 'MMM')  AS 
             summary,
             FROM x.sumy_dt c
             Group BY 1,2
             Having Count(*) &amp;gt;1;) AS c(summary, summary_dt)

/* LEFT JOIN tables b and c and replace null with zero in the summary column when 60 days (MDIFF) are missing; create derived table o and select the columns o&amp;lt;column list)*/

    LEFT JOIN 
      (SELECT
           b.LD_T,  
           b.MAX_MNTH, 
           b.tran_dt,
           c.summary,
           c.summary_dt,

            ZEROIFNULL(MDIFF( c.summary, 60 , b.tran_dt)) AS diff1,
       
              CASE
              (WHEN  diff1=0  then '2'  ELSE ' '
              END)  AS diff

              FROM  b
              GROUP BY 1,2,3,4,5
       ) AS  o ON  b.MAX_MNTH=c.summary (LD_T, MAX_MNTH,summary, 
                                         tran_dt, summary, summary_dt )
         ORDER BY 2;
     );
quit;
/*Output  data set toText File */
data _null_ ;          
    set ssd.diff ; 
    FILE  diff.txt' ;     
    PUT diff;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Oct 2017 14:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403753#M25905</guid>
      <dc:creator>dfn</dc:creator>
      <dc:date>2017-10-13T14:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/access to Teradata  create  multiple derived tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403795#M25911</link>
      <description>&lt;P&gt;Your code does not look valid. If you want to run a pass-thru query to create a SAS dataset it should look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table XX as
select * from connection to teradata
(  
....teradata code goes here....
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But in addition the code you posted does not look valid at all. It has many extra semi-colons in the middle of it and in general seems to have many extra random select clauses.&amp;nbsp; Re formatting it to use a consistent style would help make it more readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want help with writing the code you should post some example input and result data in the form of SAS data steps so that others can create sample data to test your summary logic.&amp;nbsp; If you need help with Teradata specific syntax like the ROW_NUMBER() function or the PARTITION BY keyword then a SAS forum is not the right place.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 05:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403795#M25911</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-13T05:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/access to Teradata  create  multiple derived tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403876#M25920</link>
      <description>I will reformat it. Yes, there is a lot wrong with my query syntax and I was hoping someone will help me because I am very new to sas access to Teradata&lt;BR /&gt;</description>
      <pubDate>Fri, 13 Oct 2017 12:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403876#M25920</guid>
      <dc:creator>dfn</dc:creator>
      <dc:date>2017-10-13T12:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/access to Teradata  create  multiple derived tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403926#M25925</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table xxx as 
select * from connection to teradata
 (SELECT
 FROM
 b.LD_T,
 b.K_KY

/* create derived table b and select the columns– extracts K_KY dates in the format of example SEP and print the K_KY largest count - b(&amp;lt;column list&amp;gt;)*/

 (select
 b.LD_T,
 b.K_KY
 cast(cast( b.K_KY as char(3)) as date format 'MMM') AS MAX_MNTH,
 cast(cast(b.K_KY as char(8)) as date format 'yyyymmdd') AS tran_dt
 from dy b
 Group BY 1,2
 Having Count(*) &amp;gt;1;) AS b(LD_T, MAX_MNTH, tran_dt)

/* create derived table c and select the columns – extracts sumary_end-dt dates in the format for example SEP and print the sumary_end-dt largest count b(&amp;lt;column list&amp;gt;)*/ */

 (SELECT
 FROM
 c.sumary_end_dt
 ( SELECT
 c.sumary_end_dt
 cast(cast( a.sumary_end_dt as char(3)) as date format 'MMM') AS 
 summary,
 FROM x.sumy_dt c
 Group BY 1,2
 Having Count(*) &amp;gt;1;) AS c(summary, summary_dt)

/* LEFT JOIN tables b and c and replace null with zero in the summary column when 60 days (MDIFF) are missing; create derived table o and select the columns o&amp;lt;column list)*/

 LEFT JOIN 
 (SELECT
 b.LD_T, 
 b.MAX_MNTH, 
 b.tran_dt,
 c.summary,
 c.summary_dt,

 ZEROIFNULL(MDIFF( c.summary, 60 , b.tran_dt)) AS diff1,
 
 CASE
 (WHEN diff1=0 then '2' ELSE ' '
 END) AS diff

 FROM b
 GROUP BY 1,2,3,4,5
 ) AS o ON b.MAX_MNTH=c.summary (LD_T, MAX_MNTH,summary, 
 tran_dt, summary, summary_dt )
 ORDER BY 2;
 );
quit;
/*Output data set toText File */
data _null_ ; 
 set ssd.diff ; 
 FILE diff.txt' ; 
 PUT diff;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 18:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/403926#M25925</guid>
      <dc:creator>dfn</dc:creator>
      <dc:date>2017-10-13T18:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/access to Teradata  create  multiple derived tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/404069#M25936</link>
      <description>I have reformatted the teradata query . Can you tell me why my derived tables aren't working? I am having problem with the Left join and the derived table o</description>
      <pubDate>Fri, 13 Oct 2017 18:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/404069#M25936</guid>
      <dc:creator>dfn</dc:creator>
      <dc:date>2017-10-13T18:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS/access to Teradata  create  multiple derived tables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/404071#M25937</link>
      <description>&lt;P&gt;Your TD code does not look like valid code.&amp;nbsp; Can you run that code on your TD server using Teradata SQL assistant?&lt;/P&gt;
&lt;P&gt;IN general an SQL query should be of the form&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select ....
from ...
where ...
group by ....
having ....
order by ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where just the SELECT and FROM clauses are required.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 18:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-access-to-Teradata-create-multiple-derived-tables/m-p/404071#M25937</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-13T18:42:39Z</dc:date>
    </item>
  </channel>
</rss>

