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)
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;
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.