【问题标题】:Using SAS macro使用 SAS 宏
【发布时间】:2020-11-02 20:47:01
【问题描述】:

代码如下:

%macro do_regression(dep);

proc glimmix data=xxx;

class group id intv month1;

model &dep = group month1 group*month1/d=normal link=identity;

random intv(id);

lsmeans group*month1/ilink diff  cl ;

lsmestimate group*month1 'bsl-3 ' 1 -1 0 0 -1 1 0 0/cl ;

lsmestimate group*month1 'bsl-6' 1 0 -1 0 -1 0 1 0/cl;

ods output LSMEstimates

run; quit;

%mend;

 

%do_regression(original total domain1)

以下是数据结构示例:

问题:我是 SAS 宏的新手,我正在使用 SAS 宏代码来为三个结果变量(原始总域 1)运行以下回归模型。我使用以下方法输出结果: ods output LSMEstimates 创建了三个名为 data1-data3 的数据集和估计值。但是,我无法弄清楚如何附加这些数据集的结果变量名称。最终,我只希望将以下内容存储在一个最终数据集中,该数据集可以“设置”data1-data3:影响标签估计下限。 [我只想存储我正在输出的两个 lsmestimate 语句的估计值:ods output LSMEstimates]

【问题讨论】:

  • 你能提供一个可行的小例子吗?我们无法通过运行它来测试任何东西,因为我们没有任何数据。或者使用 SASHELP 库或 GLIMMIX 文档示例中的数据集找到一组类似的代码。
  • @Reeza 谢谢。我添加了数据结构的示例。
  • 你只是问如何使用ODS OUTPUT语句? ods output LSMEstimates=&dep; 还是你问三个数据集怎么组合?
  • @Tom 谢谢!是的,我想将这些结果中的每一个设置到一个数据集中,并能够识别最终文件中的估计值来自哪个因变量。

标签: sas sas-macro


【解决方案1】:

要聚合数据集,您可以使用 PROC APPEND。

ods output LSMEstimates=lsm;
run;quit;
proc append data=lsm base=lsm_aggregate force;
run;

如果值/变量 &DEP 不在 ODS OUTPUT 语句生成的数据集中,则添加一个步骤来添加它。

data lsm_dep ;
  length dep $32 ;
  dep = "&dep";
  set lsm;
run;
proc append data=lsm_dep base=lsm_aggregate force;
run;

确保在运行新一批模型之前删除 LSM_AGGREGATE 数据集。

proc delete data=lsm_aggregate; run;
%do_regression(original )
%do_regression(total )
%do_regression(domain1)

【讨论】:

  • 非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多