DATA Step, Macro, Functions and more

Where Condition

Accepted Solution Solved
Reply
Regular Contributor
Posts: 212
Accepted Solution

Where Condition

[ Edited ]

Hi. I'm wondering if this is the best way to code a join based on the requirement that multiple variables must match in my Where condition?  

 

In my original code imb_code was unique for each record, but now I've found that both spm_calc_batch_date and imb_code make a record unique so I need to update the query.

 

select rpad('PIECES MISSING IN IV',300) as RULE_NM, 
       	actual_dlvry_date as AD_DT, 
	rpad(imb_code,31) as IMB_CODE, 
	999.1 as RULE_ORDER,
	spm_calc_batch_date
from ivprl.bi_spm_piece_bids_recon
where imb_code||trunc(spm_calc_batch_date) not in(select imb_code||trunc(spm_calc_batch_date) 
from ivprl.bi_spm_piece_iv_recon)

 


Accepted Solutions
Solution
‎05-06-2016 11:09 AM
Super User
Super User
Posts: 7,942

Re: Where Condition

Posted in reply to buechler66

Hi,

 

No test data/required output to show what is happening.  "Best" is always subjective.  You could replace some of the code with cats as below, you could left join the smaller table onto the main (probably less resource hungry if data is large) or you could do it in datastep which is probably the least resouce hungry of the lot.  Without any kind of parameters its just guessing :

 

select rpad('PIECES MISSING IN IV',300) as RULE_NM, 
       actual_dlvry_date as AD_DT, 
       rpad(imb_code,31) as IMB_CODE, 
       999.1 as RULE_ORDER,
       spm_calc_batch_date
from   ivprl.bi_spm_piece_bids_recon
where  cats(imb_code,spm_calc_batch_date) not in(select distinct cats(imb_code,spm_calc_batch_date) from ivprl.bi_spm_piece_iv_recon)

Datastep:

/* assumes sorted*/
data want;
  merge ivprl.bi_spm_piece_bids_recon (in=a)
        ivprl.bi_spm_piece_iv_recon (in=b);
  by imb_code spm_calc_batch_date;
  if a and b;
run;

View solution in original post


All Replies
Solution
‎05-06-2016 11:09 AM
Super User
Super User
Posts: 7,942

Re: Where Condition

Posted in reply to buechler66

Hi,

 

No test data/required output to show what is happening.  "Best" is always subjective.  You could replace some of the code with cats as below, you could left join the smaller table onto the main (probably less resource hungry if data is large) or you could do it in datastep which is probably the least resouce hungry of the lot.  Without any kind of parameters its just guessing :

 

select rpad('PIECES MISSING IN IV',300) as RULE_NM, 
       actual_dlvry_date as AD_DT, 
       rpad(imb_code,31) as IMB_CODE, 
       999.1 as RULE_ORDER,
       spm_calc_batch_date
from   ivprl.bi_spm_piece_bids_recon
where  cats(imb_code,spm_calc_batch_date) not in(select distinct cats(imb_code,spm_calc_batch_date) from ivprl.bi_spm_piece_iv_recon)

Datastep:

/* assumes sorted*/
data want;
  merge ivprl.bi_spm_piece_bids_recon (in=a)
        ivprl.bi_spm_piece_iv_recon (in=b);
  by imb_code spm_calc_batch_date;
  if a and b;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 177 views
  • 1 like
  • 2 in conversation