SAS动态声明宏变量 [英] SAS dynamically declaring macro variable

查看:35
本文介绍了SAS动态声明宏变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司刚刚从 R 切换到 SAS,我正在将很多 R 代码转换为 SAS.我在 SAS 中动态声明变量(宏变量)时遇到了一个大问题.

My company just switched from R to SAS and I am converting a lot of my R code to SAS. I am having a huge issue dynamically declaring variables (macro variables) in SAS.

例如,我的一个流程需要取一列的平均值,然后在许多步骤中将其应用于整个代码.

For example one of my processes needs to take in the mean of a column and then apply it throughout the code in many steps.

%let numm =0;

我已经用我的 numm 变量尝试了以下方法,但两种方法都不起作用,而且我似乎在网上找不到任何东西.

I have tried the following with my numm variable but both methods do not work and I cannot seem to find anything online.

PROC MEANS DATA = ASSGN3.COMPLETE mean;
#does not work
&numm = VAR MNGPAY;
run;

Proc SQL;
#does not work
&numm =(Select avg(Payment) from CORP.INV);
quit;

推荐答案

我强烈建议您购买有关 SAS 的书籍或参加 SAS Training 的课程.SAS Programming II 是一个很好的起点(如果您还没有编程其他任何东西,则编程 I,但听起来并非如此).您拥有的代码表明您需要它.它是 R 的完整范式转变.

I would highly recommend buying a book on SAS or taking a class from SAS Training. SAS Programming II is a good place to start (Programming I if you have not programmed anything else, but that doesn't sound like the case). The code you have shows you need it. It is a complete paradigm shift from R.

也就是说,试试这个:

proc sql noprint;
select mean(payment) into :numm from corp.inv;
quit;

%put The mean is: &numm;

这篇关于SAS动态声明宏变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆