BookmarkSubscribeRSS Feed
Sukhi1
Calcite | Level 5

 proc sql;
        create table work.EXUPL_GVA2_&YYMM. as

        select R.*,
               S.FIL as FILMAP, S.KTO as KTOMAP
         from  work.EXUPL_GVA1_&YYMM. as R

          left join LIB_CLNT.CLIENT2SEGMENT_FKN_FINAL_&YYMM.
               (where =( FIL and KTO <=0)) as S
           on  R.ORG_ID=S.ORG_ID
          ;
  quit;

  data work.EXUPL_GVA3_&YYMM.;
       set work.EXUPL_GVA2_&YYMM.;

           if KTO eq 9999989 and KTOMAP not in (. 9999989) then do;

              FIL=FILMAP;
              KTO=KTOMAP;

           end;
  run;

  proc sql;
       create table work.EXUPL_GVA4_&YYMM. as
             select R.*
                   ,S.PCC
                   ,S.GBM
             from  work.EXUPL_GVA2_&YYMM. as R
             left  join LIB_CLNT.CLIENT_MASTER_&YYMM. as S
             on    R.FIL=S.FIL and R.KTO=S.KTO
             ;
  quit;

3 REPLIES 3
sidpesar
Obsidian | Level 7

on work.EXUPL_GVA4_&YYMM from table is EXUPL_GVA2_&YYMM. or EXUPL_GVA3_&YYMM

the below code will work if you want to use EXUPL_GVA3_&YYMM to create work.EXUPL_GVA4_&YYMM.

 

 

PROC SQL;
CREATE TABLE WORK.EXUPL_GVA4_&YYMM. AS

SELECT
S.FIL AS FILMAP, 
S.KTO AS KTOMAP,
(CASE WHEN S.KTO EQ 9999989 AND S.KTOMAP NOT IN (. 9999989) THEN S.FIL) END) AS FIL,
(CASE WHEN S.KTO EQ 9999989 AND S.KTOMAP NOT IN (. 9999989) THEN S.KTO) END) AS KTO, 
S.PCC,
S.GBM,
R.*

FROM  
WORK.EXUPL_GVA1_&YYMM. AS R
LEFT JOIN LIB_CLNT.CLIENT2SEGMENT_FKN_FINAL_&YYMM.(WHERE =( FIL AND KTO <=0)) AS S
ON  R.ORG_ID=S.ORG_ID
LEFT JOIN LIB_CLNT.CLIENT_MASTER_&YYMM. AS S1
ON    S.FIL=S1.FIL AND S.KTO=S1.KTO;
QUIT;
ballardw
Super User

Optimize can mean several things: Create code that runs in minimum execution time; uses minimum disk or memory; minimizes code lines; runs robustly in spite of "bad" data and I'm sure a few more could be considered.

 

Which do you mean to optimize?

 

 

Sukhi1
Calcite | Level 5
Hi ,
For now minimum lines of code and less execution time would be good for me.
Thanks a lot

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 822 views
  • 0 likes
  • 3 in conversation