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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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