DATA Step, Macro, Functions and more

Kindly convert Oracle sql code to SAS Code

Accepted Solution Solved
Reply
Contributor
Posts: 47
Accepted Solution

Kindly convert Oracle sql code to SAS Code

I want to convert below Oracle sql code into SAS sql code, how to proceed?

 

 

create or replace
PROCEDURE AUTO_PRM_INDICATION_VEH_CTGRY
(
  START_YEAR IN NUMBER 
, END_YAER IN NUMBER 
) AS
 SOURCE_SYSTEM VARCHAR(500) := '(2,3,4,14,15)';
POLICY_TYPE VARCHAR(500):= '(1,15)';

BEGIN

 
    --STEP1: GET COVERAGE INFO   
    --DELETE IF TABLE EXIST
    DELOBJECT ('tcoverages_summary','TABLE');  
   
    EXECUTE IMMEDIATE ('create table tcoverages_summary as
    SELECT  /*+ PARALLEL */
            T1.POLICY_TYPE_SK,
            T1.source_system_sk,
            T2.ACTUAL_DT,
            EXTRACT(YEAR FROM T2.ACTUAL_DT) as  YEAR_CT,
            EXTRACT(MONTH FROM T2.ACTUAL_DT) as MONTH_CT,
            T1.INTCOV_SK,
            T1.policy_sk,
            T1.item_attribute_sk,
            T1.EARNED_XPSR_AM,
            T1.WRITTEN_XPSR_AM,
            T1.MTD_WRITTEN_PRM_AM,
            T1.EARNED_PRM_AM,
            T3.VEHICLE_CATEGORY_TX
    FROM                 TCOVERAGES_SUMMARY@MISP.AIG.COM T1
    LEFT JOIN
            Tdate@MISP.AIG.COM T2
    on
            (T1.MONTH_SK = T2.DATE_SK)
    LEFT JOIN
            TVEHICLE@MISP.AIG.COM T3
    on
            (T1.ITEM_SK = T3.VEHICLE_SK)
    WHERE   T1.POLICY_TYPE_SK IN '|| POLICY_TYPE ||' and
            T1.source_system_sk NOT IN '|| SOURCE_SYSTEM ||' AND
            T1.SNAPSHOT_TYPE_IN = 0 AND
            EXTRACT(YEAR FROM T2.ACTUAL_DT)>= '||START_YEAR||' AND
            EXTRACT(YEAR FROM T2.ACTUAL_DT)<= '||END_YAER||'');
           


Accepted Solutions
Solution
‎06-25-2016 11:12 AM
Super User
Super User
Posts: 7,419

Re: Kindly convert Oracle sql code to SAS Code

Sorry, by what do you mean convert this, that code creates a procedure - these are not available outside the database.  At a brief glimpse over the code you appear to be using a fair bit which is database specific - for example the function extract(), not sure what that does.  Also some questions, where do the from tables exist, will it still be the database, if so then you either need to libname to them, or use pass-through.  Also, can this not be done on the database and a view created, so that for SAS its just a select * from xyz?

proc sql;
  create table WANT as
  SELECT  T1.POLICY_TYPE_SK,
            T1.source_system_sk,
            T2.ACTUAL_DT,
            EXTRACT(YEAR FROM T2.ACTUAL_DT) as  YEAR_CT,  <- change
            EXTRACT(MONTH FROM T2.ACTUAL_DT) as MONTH_CT,  <- change
            T1.INTCOV_SK,
            T1.policy_sk,
            T1.item_attribute_sk,
            T1.EARNED_XPSR_AM,
            T1.WRITTEN_XPSR_AM,
            T1.MTD_WRITTEN_PRM_AM,
            T1.EARNED_PRM_AM,
            T3.VEHICLE_CATEGORY_TX
    FROM                 TCOVERAGES_SUMMARY@MISP.AIG.COM T1  <- where are the tables going to reside?
    LEFT JOIN
            Tdate@MISP.AIG.COM T2
    on
            (T1.MONTH_SK = T2.DATE_SK)
    LEFT JOIN
            TVEHICLE@MISP.AIG.COM T3
    on
            (T1.ITEM_SK = T3.VEHICLE_SK)
    WHERE   T1.POLICY_TYPE_SK IN '|| POLICY_TYPE ||' and  <- are these text strings of cuntion parameters?
            T1.source_system_sk NOT IN '|| SOURCE_SYSTEM ||' AND
            T1.SNAPSHOT_TYPE_IN = 0 AND
            EXTRACT(YEAR FROM T2.ACTUAL_DT)>= '||START_YEAR||' AND
            EXTRACT(YEAR FROM T2.ACTUAL_DT)<= '||END_YAER||'');  <- appears to be a typo
quit;

View solution in original post


All Replies
Solution
‎06-25-2016 11:12 AM
Super User
Super User
Posts: 7,419

Re: Kindly convert Oracle sql code to SAS Code

Sorry, by what do you mean convert this, that code creates a procedure - these are not available outside the database.  At a brief glimpse over the code you appear to be using a fair bit which is database specific - for example the function extract(), not sure what that does.  Also some questions, where do the from tables exist, will it still be the database, if so then you either need to libname to them, or use pass-through.  Also, can this not be done on the database and a view created, so that for SAS its just a select * from xyz?

proc sql;
  create table WANT as
  SELECT  T1.POLICY_TYPE_SK,
            T1.source_system_sk,
            T2.ACTUAL_DT,
            EXTRACT(YEAR FROM T2.ACTUAL_DT) as  YEAR_CT,  <- change
            EXTRACT(MONTH FROM T2.ACTUAL_DT) as MONTH_CT,  <- change
            T1.INTCOV_SK,
            T1.policy_sk,
            T1.item_attribute_sk,
            T1.EARNED_XPSR_AM,
            T1.WRITTEN_XPSR_AM,
            T1.MTD_WRITTEN_PRM_AM,
            T1.EARNED_PRM_AM,
            T3.VEHICLE_CATEGORY_TX
    FROM                 TCOVERAGES_SUMMARY@MISP.AIG.COM T1  <- where are the tables going to reside?
    LEFT JOIN
            Tdate@MISP.AIG.COM T2
    on
            (T1.MONTH_SK = T2.DATE_SK)
    LEFT JOIN
            TVEHICLE@MISP.AIG.COM T3
    on
            (T1.ITEM_SK = T3.VEHICLE_SK)
    WHERE   T1.POLICY_TYPE_SK IN '|| POLICY_TYPE ||' and  <- are these text strings of cuntion parameters?
            T1.source_system_sk NOT IN '|| SOURCE_SYSTEM ||' AND
            T1.SNAPSHOT_TYPE_IN = 0 AND
            EXTRACT(YEAR FROM T2.ACTUAL_DT)>= '||START_YEAR||' AND
            EXTRACT(YEAR FROM T2.ACTUAL_DT)<= '||END_YAER||'');  <- appears to be a typo
quit;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 167 views
  • 0 likes
  • 2 in conversation