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

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)

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

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!

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.

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
  • 1 reply
  • 681 views
  • 1 like
  • 2 in conversation