BookmarkSubscribeRSS Feed
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I'm wondering about the "where" clause in sql code. I need to apply the where clause in the beginning only for the PSAEU11.DB_DOSSIER data, but I suppose that my syntaxe is not right. 

 


proc  sql;
create table test as select rga.cd_rga,sousc.no_police from PSAEU11.db_dossier sousc (where sousc.cd_dossier = 'SOUSC' and sousc.lp_etat_doss not in ('ANNUL','A30','IMPAY') and sousc.no_police = 'I99300001') left join  PSAEU11.db_garantie gar on sousc.is_protocole=gar.is_protocole and gar.cd_garantie='DEDIE' 
    left join PSAEU11.db_ctrat_support ctrats on ctrats.is_garantie = gar.is_garantie and ctrats.is_dossier = sousc.is_dossier 
    left join PSAEU11.db_param_mandat_op mandaop on ctrats.is_param_mandat_op = mandaop.is_param_mandat_op  
    left join PSAEU11.db_rga rga on mandaop.is_rga=rga.is_rga ;
	quit;

Thank you for your help ! 

2 REPLIES 2
PhilC
Rhodochrosite | Level 12

This is where some SAS is interjected into SQL syntax for PROC SQL, namely the SAS dataset options.  Try this

replace this

/*...*/
from PSAEU11.db_dossier sousc (where sousc.cd_dossier = 'SOUSC' and sousc.lp_etat_doss not in ('ANNUL','A30','IMPAY') and sousc.no_police = 'I99300001') left join /*...*/

with this

/*...*/
from PSAEU11.db_dossier (where=(cd_dossier = 'SOUSC' and lp_etat_doss not in ('ANNUL','A30','IMPAY') and no_police = 'I99300001')) as sousc left join /*...*/

This little example works as well

proc sql;
   select cars.Make, cars.model
     from SASHELP.CARS(where=(Make="Audi")) as cars;
quit;
utrocketeng
Quartz | Level 8

give this a whirl...

proc  sql;
create table test as 
select rga.cd_rga,sousc.no_police 
from 
	(SELECT * FROM PSAEU11.db_dossier where cd_dossier = 'SOUSC' and lp_etat_doss not in ('ANNUL','A30','IMPAY') and no_police = 'I99300001') sousc
	left join PSAEU11.db_garantie gar on sousc.is_protocole=gar.is_protocole and gar.cd_garantie='DEDIE' 
    left join PSAEU11.db_ctrat_support ctrats on ctrats.is_garantie = gar.is_garantie and ctrats.is_dossier = sousc.is_dossier 
    left join PSAEU11.db_param_mandat_op mandaop on ctrats.is_param_mandat_op = mandaop.is_param_mandat_op  
    left join PSAEU11.db_rga rga on mandaop.is_rga=rga.is_rga 
;
quit;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1389 views
  • 1 like
  • 3 in conversation