Hi Paige Miller, I work on a study and I was instructed to generate Cartesian Product from 2 datasets applying 2 filter conditions, to ensure the respective records only needs to be used. Also I was instructed not to use direct Cartesianing techniques like PROC SQL or DATA step POINT statement. I tried this using PROC SQL macro variables creation method (PROC SQL; select records into :rec_&i.&j from <dataset> where <var1>=1 and <var2>=1;quit ). However, we have many values in 2 filter variables, due to which I need to write many PROC SQL steps in OPEN code. So I thought I could create a macro to iterate the nested loop. %macro rec_list; %do i=1 %to 3; %do j=1 %to 4; proc sql; select records into :rec_list_&i.&j. seperated by " " from ABC where VAR1=&i AND VAR2=&j; select count(*) into :n_list_&i.&j. from ABC where VAR1=&i AND VAR2=&j; quit; %end; %end; %mend; %rec_list; %put &rec_list_11.; %macro loop (j=, outds=, v1=, v2=); data a11&v1.&v2.; set a1; if var1=&v1. and var2=&v2. ; run; data a_&outds.; set a11&v1.&v2.; %do i=1 %to &&n_&outds.; %let rec=%scan(&&rec_list&outds.., &i, 1234567890-,k); record="&rec."; output; %end; run; %mend loop; %loop (j=1, outds=11, v1=1, v2=1); %loop (j=1, outds=12, v1=1, v2=2); On running above code macro variables are generated but I could not see macro variables resolving. After I use %global statement, I can see macro variables resolving and I deleted them using %symdel at last of the pgm to avoid confusion or overwriting of Global Macro variables.
... View more