www.sas.com > SAS UK > In the Know Homepage Search | Contact Us    
SAS UK Newsletter Banner SAS - The power to know(tm)  

How Do You Retrieve Data from Indexed Datasets for a Handful of Members Only?

(Written By Jim Jeffrey, BCA)

The following code determines how many records you wish to retrieve data for and then creates the same amount of macro variables, each one containing the key value that you wish to retrieve. These macro values are then queried in a where statement.


%macro get_custs; 
proc sql noprint; 
select count(*) into :num_custs from sample_file; 
%let num_custs = &num_custs; 
select cust_ref into :cust1 - :cust&num_custs from sample_file; 
quit; 
data retrieved_customers; 
set indexed_master_file; 
where cust_ref in (%do i=1 %to &num_custs; "&&cust&i" %end;); 
run; 
%mend get_custs; 
%get_custs;