SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TheNovice
Quartz | Level 8

hi, I can't get this query to work...

 

I am trying to extract records with code S from COL table where IDis from another table (not oracle)

 

I have tried the 2 variations below but both given an error. What am i doing wrong ? Appreciate any direction


proc sql;
 CONNECT TO ORACLE (user=&name  pw=&pass  path=Ex);
 create table SUS as
  select * from connection to oracle
  (select ID,COL_ACTV_CODE,max(COL_ACTV_DATE)
   from  ods.COL
   group by ID
   where COL_ACTV_CODE = 'S'
   
       )
   WHERE ID IN (SELECT  ID FROM TEST1)
 ;
 disconnect from oracle;
quit;

 

 


proc sql;
 CONNECT TO ORACLE (user=&name  pw=&pass  path=Ex);
 create table SUS as
  select * from connection to oracle
  (select ID,COL_ACTV_CODE,max(COL_ACTV_DATE)
   from  ods.COL
   group by ID
   having COL_ACTV_CODE = 'S'
   
       )
   WHERE ID IN (SELECT  ID FROM TEST1)
 ;
 disconnect from oracle;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Your WHERE statement must go before the GROUP BY. Please note you will have a re-merging data problem as COL_ACTV_CODE isn't included in your GROUP BY.

proc sql;
 CONNECT TO ORACLE (user=&name  pw=&pass  path=Ex);
 create table SUS as
  select * from connection to oracle
  (select ID,COL_ACTV_CODE,max(COL_ACTV_DATE)
   from  ods.COL
  where COL_ACTV_CODE = 'S'
   group by ID
  )
   WHERE ID IN (SELECT  ID FROM TEST1)
 ;
 disconnect from oracle;
quit;

 

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

Your WHERE statement must go before the GROUP BY. Please note you will have a re-merging data problem as COL_ACTV_CODE isn't included in your GROUP BY.

proc sql;
 CONNECT TO ORACLE (user=&name  pw=&pass  path=Ex);
 create table SUS as
  select * from connection to oracle
  (select ID,COL_ACTV_CODE,max(COL_ACTV_DATE)
   from  ods.COL
  where COL_ACTV_CODE = 'S'
   group by ID
  )
   WHERE ID IN (SELECT  ID FROM TEST1)
 ;
 disconnect from oracle;
quit;

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 2077 views
  • 0 likes
  • 2 in conversation