Hi jen123, I would like to share 3 approaches that I've tried to answer your question. Datasets: 1. Customer_Info Customer_ID No Street_Name City State 170927308313 123 Elks Grove Chicago IL 171540339727 456 Crab Lake Baltimore MD 170060423416 7890 Winery Lane Frederick MD 170869014929 2468 Lombardi Drive San Francisco CA 111870069510 13579 PCH San Diego CA 165019812149 22226 Reunion Blvd Dallas TX 172270371229 11597 Gulf Drive Tampa Fl 2. Customer_Range (I modified the values to easily see what gets extracted) Customer_ID_L Customer_ID_H 170000000000 171000000000 110000000000 120000000000 1st approach 1. Create a 'Summary' dataset merging both datasets, much like an outer join. proc sql; create table summary as select * from Customer_Info, Customer_Range ; quit; 2. Use DATA step to do the extract of intended data and output to another dataset. data Promoted; set summary; if Customer_ID ge Customer_ID_L and Customer_ID le Customer_ID_H then output; drop Customer_ID_L Customer_ID_H; run; 2nd approach (Use Call Execute) 1. The main logic is to iterate through the Customer_Range dataset, i.e. per observation, comparing the Customer_ID from Customer_Info dataset, to the range. The set of record that results to true condition is extracted to TEMP dataset. Afterwhich, PROMOTED dataset consolidates all data for all ranges. data _null_; set Customer_Range; call execute(' data temp; set Customer_Info; if Customer_ID ge '||Customer_ID_L||' and Customer_ID le '||Customer_ID_H||' then output; run; proc append base=Promoted data=temp force; run; '); run; You can study Call Execute through http://www2.sas.com/proceedings/sugi22/CODERS/PAPER86.PDF and other sources on the web. 3rd approach (Use macro facility) 1. Create macro variables for count of observations in the Customer_Range and for the actual range values. proc sql noprint; select catt(count(1)) into :CustRange_Cnt from Customer_Range; select Customer_ID_L format 13., Customer_ID_H format 13. into :Customer_ID_L1-:Customer_ID_L&CustRange_Cnt, :Customer_ID_H1-:Customer_ID_H&CustRange_Cnt from Customer_Range; quit; 2. Main logic is much similar to 2nd approach. The main difference is that in this process, the macro variables will then be used as values for count and fulfilling conditions. %macro getPromoted; %do i=1 %to &CustRange_Cnt; data temp; set Customer_Info; if Customer_ID ge &&Customer_ID_L&i and Customer_ID le &&Customer_ID_H&i then output; run; proc append base=promoted data=temp force; %end; %mend getPromoted; %getPromoted; You may study macro in http://www2.sas.com/proceedings/sugi29/243-29.pdf and other sources in the web. *NOTE: for 2nd and 3rd approaches, you may need to add a check if PROMOTED dataset exists, then drop/delete it before your next run since I used PROC APPEND which will just append data from previously created one. Hope this helps answer your question.
... View more