SAS Loop

Hello community I am having problems in making SAS do this statements for several times: I want the code to execute first with i = 1, then with i = 2 and so on...
I know is a basic doubt, but I'd appreciate your help.
Best regards

proc sort data=Outlets_new;
by restatementGroup;
Proc sort data=MBD_i;
by restatementGroup;
Data Outlets_new2;
merge Outlets_new MBD_i;
by restatementGroup;

data Outlets_new2;
Set Outlets_new2;
if mbdID = i;
It looks like a problem for a SAS macro but your description is a bit confusing.

Is one to assume that you already have datasets sequentially called “MBD_1”, “MBD_2”, “MBD_3”, … “MBD_n” where “n” is the number of “MBD_” datasets?

Does the “_i” name suffix not also apply to the “Outlets_new” datasets? If not, you need to sort “Outlets_new” once only, not in the loop. Also, if you iterate your code as you have shown it, the dataset “Outlets_new2” from the previous iteration is simply overwritten by the latest one in the final “data” step, so the purpose of this exercise is obscure to say the least.

Maybe you should show what you want to achieve with an example. :confused: