SAS:在宏程序的循环中使用动态宏变量
SAS: use dynamic macro variable in loop in macro program
我想达到同样的效果:
data train_Sex(keep=Name Sex) train_Age(keep=Name Age) train_Height(keep=Name Height) train_Weight(keep=Name Height);
set sashelp.class;
run;
使用带有变量列表的宏程序。
据我所知:
* Build macro program;
%macro build_sets(var_list);
%let nwords = %sysfunc(countw(&var_list));
%do i=1 %to &nwords;
call symput("variable", %scan(&var_list, i));
data train_&variable(keep=Name &variable);
set sashelp.class;
run;
%end;
%mend;
* Run it;
%let var_list = Sex Age Height Weight;
%build_sets(&var_list);
但我不知道如何动态更改 "variable" var.
谢谢!
类似问题:
1.SAS dynamically declaring macro variable
2. Using a dynamic macro variable in a call symput statement
3.
你很接近。下面的东西应该适合你。调用 symput 是 datastep 的一部分,用于从 dvariables 创建宏变量,因此是问题。
%macro build_sets(var_list);
;
%do i=1 %to %sysfunc(countw(&var_list));
%let variable= %scan(&var_list, &i));
data train_&variable(keep=Name &variable);
set sashelp.class;
run;
%end;
%mend;
* Run it;
%let var_list = Sex Age Height Weight;
%build_sets(&var_list);
我想达到同样的效果:
data train_Sex(keep=Name Sex) train_Age(keep=Name Age) train_Height(keep=Name Height) train_Weight(keep=Name Height);
set sashelp.class;
run;
使用带有变量列表的宏程序。 据我所知:
* Build macro program;
%macro build_sets(var_list);
%let nwords = %sysfunc(countw(&var_list));
%do i=1 %to &nwords;
call symput("variable", %scan(&var_list, i));
data train_&variable(keep=Name &variable);
set sashelp.class;
run;
%end;
%mend;
* Run it;
%let var_list = Sex Age Height Weight;
%build_sets(&var_list);
但我不知道如何动态更改 "variable" var.
谢谢!
类似问题:
1.SAS dynamically declaring macro variable
2. Using a dynamic macro variable in a call symput statement
3.
你很接近。下面的东西应该适合你。调用 symput 是 datastep 的一部分,用于从 dvariables 创建宏变量,因此是问题。
%macro build_sets(var_list);
;
%do i=1 %to %sysfunc(countw(&var_list));
%let variable= %scan(&var_list, &i));
data train_&variable(keep=Name &variable);
set sashelp.class;
run;
%end;
%mend;
* Run it;
%let var_list = Sex Age Height Weight;
%build_sets(&var_list);