I will give an example of code for the standard CARS (page 23) from the SASHELP library:
%Macro TablesEc2 ; //Объявляем макро переменную %let macromake=; //Создаем датасет с перечнем всех производителей proc sql; create table Makers as select distinct Make from sashelp.cars; quit; //Добавляем к датасету колонку с идентификаторами data Makers; set Makers; rownum=_n_; run; proc sql; %do k=3 %to 5; //SQL запросом присваиваем макропеременной значение из датасета всех производителей select Make into :macromake from Makers where rownum = &k.; //Теперь создаем таблицу в цикле create table cars&k. as //Выбирая каждый раз столбец с новым названием select ¯omake From sashelp.cars; %end quit; %mend; %TablesEc2
However , this test example will give you an error for the reason that there are no columns with names of manufacturers in the CARS dataset. This can be fixed by making your dataset. Here I just set an example of how this should work.
It may be easier for you to initially select a column in a SQL query by some condition and only then, in a separate data step, rename it in all created datasets (macrocycle to help) .
Hope that helped you. If there are additional questions - ask in the comments.
colnames? In your case, the % scan macro function is not as you want) - Sanek Zhitnik