BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
subrat1
Fluorite | Level 6

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||'');
           

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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