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

Hi all, 

 

Below is a proc sql Oracle  query I’ve written which pulls various promotion history based on elements in a string var.   I would like very much to use regular expressions as opposed to a bunch of LIKE functions. I’m having trouble figuring out how to do this in the Oracle environment. The section of the query I would like to modify using regular expressions is this:

 

and t1.segment_key not like '%N'

and t1.segment_key not like '%C'

and t1.segment_key not like 'CNM'

and (t2.client_promo_id like 'PD%'

or t2.client_promo_id like 'FD%'

or t2.client_promo_id like 'RD%' 

or t2.client_promo_id like 'PE%'

or t2.client_promo_id like 'FE%'

or t2.client_promo_id like 'RE%'

or t2.client_promo_id like 'RLS%'

or t2.promotion_title like '%RL%')

and t2.promotion_title not like '%RGB%'

and t2.promotion_title not like '%Rugby%'

 

Any assistance will be greatly appreciated. Thanks!

 

 

Full query: 

 

proc sql;
connect to oracle (user=xxx path='xxx');
create table Want as
select  * from connection to oracle (
select    
t1.customer_id, 
count(distinct case when t1.promotion_type=1 then t1.promotion_id end) as dm_ttl,
count(distinct case when t1.promotion_type=2 then t1.promotion_id end) as email_ttl
from sas_promo_history_vw t1 join sas_promotion_vw t2       
 on  t1.promotion_id=t2.promotion_id
where t1.promotion_type in (1,2)
and t2.in_home_date between &start_date. and &End_date.
and t1.segment_key not like '%N' 
and t1.segment_key not like '%C' 
and t1.segment_key not like 'CNM' 
and (t2.client_promo_id like 'PD%' 
or t2.client_promo_id like 'FD%' 
or t2.client_promo_id like 'RD%'  
or t2.client_promo_id like 'PE%' 
or t2.client_promo_id like 'FE%' 
or t2.client_promo_id like 'RE%'
or t2.client_promo_id like 'RLS%'
or t2.promotion_title like '%RL%')
and t2.promotion_title not like '%RGB%' 
and t2.promotion_title not like '%Rugby%'
group by t1.customer_id);
disconnect from oracle;quit;
1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee
...
and not regexp_like (t1.segment_key, '[NC]$')
and t1.segment_key != 'CNM'
and (
  regexp_like (t2.client_promo_id, '^([FR]D|[PFR]E|RLS)')
  or t2.promotion_title like '%RL%' )
and not regexp_like (t2.promotion_title,'(RGB|Rugby)')
...

View solution in original post

2 REPLIES 2
FriedEgg
SAS Employee
...
and not regexp_like (t1.segment_key, '[NC]$')
and t1.segment_key != 'CNM'
and (
  regexp_like (t2.client_promo_id, '^([FR]D|[PFR]E|RLS)')
  or t2.promotion_title like '%RL%' )
and not regexp_like (t2.promotion_title,'(RGB|Rugby)')
...

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 1906 views
  • 1 like
  • 2 in conversation