I have a data called cust_sales and I would like to use macro to loop through customer unique name to filter out the record and save it as another SAS dataset. I've tried below codes and it doesn't work. Can someone help. Thanks. Desired output from below is to have 4 SAS output (Customer_Anthony, Customer_Samuel, Customer_Rebecca and Customer_Jessica). Customer_Anthony sas output will show ony 2 records, samuel will have 2 records and so on.. cust_sales dataset: /* Get unique name from current mth */ proc SQL; CREATE TABLE work.unique_name_list as SELECT DISTINCT name from work.cust_sales; QUIT; /*Loop through unique name list to output each customer name record */ %macro run_loops; %local cnt, i, cust_name; /* count unique number of cust_name */ %let dsid = %sysfunc(open(work.unique_name_list)); %let cnt = %sysfunc(attrn(&dsid, nlobs)); %let rc = %sysfunc(close(&dsid)); %do i = 1 %to &cnt; data _null_; p = &i,; set work.unique_name_list point=p; call symputx('cust_name', name); /*Filter out data based on unique customer name*/ data Customer_&cust_name.; set work.cust_sales; WHERE name = &cust_name.; run; stop; run; %end; %mend; %run_loops;
... View more