Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?

Using  SAS/ACCESS to Teradata to create multiple derived tables

Posted on 2017-10-12
0
Medium Priority
?
12 Views
Last Modified: 2017-10-13
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 on a file that runs monthly and daily. The file doesn't run on weekends or holidays.  In my query, The max_month column values are compared with the summary column values. If there are missing months in the summary column than the missing values are replaced with zeros. The last step is to output the data set to a text file.  My query isn't  outputting any results.
 
In the attachment, there is a text file name tran_sumary and an excel file name month.xls.  The tran_sumary file is a data file and month.xls is an example of what my query results need to print
 
 
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(<column list>)*/

    (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(*) >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(<column list>)*/ */

       (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(*) >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<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;

Open in new window

tran_sumary.txt
month.xlsx
0
Comment
Question by:dfn48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Join & Write a Comment

An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question