Loops SAS宏嵌套循环
我想建立一个包含两个预测因子的逻辑模型。一个来自set all_indeps1,一个来自all_indeps2。我在宏下面运行,但是,它只运行带有来自所有_indeps1的第一个变量和来自所有_indeps2的所有变量的模型。我应该如何修复宏,以便从两个集合中获得两个变量的所有可能组合 另外,我想只输出逻辑模型中每个预测值的p值,有什么想法吗 非常感谢Loops SAS宏嵌套循环,loops,macros,nested,sas,Loops,Macros,Nested,Sas,我想建立一个包含两个预测因子的逻辑模型。一个来自set all_indeps1,一个来自all_indeps2。我在宏下面运行,但是,它只运行带有来自所有_indeps1的第一个变量和来自所有_indeps2的所有变量的模型。我应该如何修复宏,以便从两个集合中获得两个变量的所有可能组合 另外,我想只输出逻辑模型中每个预测值的p值,有什么想法吗 非常感谢 %macro trivariate(all_indeps1, all_indeps2); %let k = 1; %let l = 1; %le
%macro trivariate(all_indeps1, all_indeps2);
%let k = 1;
%let l = 1;
%let indep1 = %scan(&all_indeps1, &k);
%let indep2 = %scan(&all_indeps2, &l);
%do %while("&indep1" NE "");
%do %while ("&indep2" NE "");
title "independent variable is &Indep1 and &Indep2";
proc logistic data = A descending;
model Y = &indep1 &indep2;
run;
%let l = %eval(&l + 1);
%let indep2 = %scan(&all_indeps2, &l);
%end;
%let k = %eval(&k + 1);
%let indep1 = %scan(&all_indeps1, &k );
%end;
%修补 这确实是两个问题 1.没有什么比你的宏出错更让我吃惊的了。尝试
选项mprint mlogic代码>查看更多幕后活动
我个人会将其编码为
%macro trivariate(all_indeps1, all_indeps2);
%let n1 = %sysfunc(countw(&all_indeps1));
%let n2 = %sysfunc(countw(&all_indeps2));
%do i=1 to &n1;
%let indep1 = %scan(&all_indeps1,&i);
%do j=1 %to &n2;
%let indep2 = %scan(&all_indeps2,&i);
STUFF
%end
%end;
%mend;
2.只从进程中选择1个输出。使用ods跟踪打开代码>您的过程,然后ods跟踪关闭代码>将打印放入输出目标的表名
然后可以使用ods选择代码>您的过程,然后选择默认值代码>将告诉输出交付系统(ODS)仅打印您要求的表,然后重置为默认输出。(在您的情况下,此表可能是ParameterEstimates)我根本不会将其编码为宏循环,而是将其设置为使您的宏只是内部位,并调用宏n1*n2次
假设您有两个数据集,indep1
和indep2
,其中每一个数据集都包含一列,每行一个变量名。如果您有一个宏:
%macro trivariate(indep1,indep2);
title "independent variable is &Indep1 and &Indep2";
proc logistic data = A descending;
model Y = &indep1 &indep2;
run;
%mend trivariate;
proc sql;
select cats('%trivariate(',indep1.var,',',indep2.var,')') into :trivarlist
separated by ' '
from indep1, indep2;
quit;
&trivarlist.;
除了非常简单的情况外,在宏语言之外控制重复几乎总是比在宏语言内部容易;它是一种更好的编程风格,因为它使代码更易于移植和重用