无法正确读取宏变量(Macro variable can't be read correctly)

系统教程 行业动态 更新时间:2024-06-14 16:53:13
无法正确读取宏变量(Macro variable can't be read correctly)

我的目的很简单。 只想为数据集提供一些值。 有两个步骤。 首先,将值读入宏变量。 其次,将宏变量传递给数据集。 代码是:

首先,创建宏变量。

proc sql; select procdate, prim,side,orgnname,orgnid,OrgnStTe into :procdate, :prim, :side, :orgnname, :orgnid, :OrgnStTe from ours where objid=783125; quit;

这一步很有效。 然后传递值。

data test; set m1; if id=184 then DO; objid=783125;procdate=&procdate.;prim=&prim.;side=&side.;orgnname=&orgnname.;orgnid=&orgnid.;OrgnStTe=&OrgnStTe.; END; run;

对于此步骤,错误大约是orgnname。 对错误不太确定。 我尝试了%bquote(&orgnname。)和%str(&orgnname。)。 两者都不起作用。

注意:由宏变量“ORGNNAME”生成的行。 1 CALVARY JOHN JAMES MEMORIAL HOSPITAL ---- 388 76 ERROR 388-185:期待算术运算符。

错误76-322:语法错误,语句将被忽略。

my purpose is pretty simple. Just want to give some values to datasets. There are 2 steps. First, is read the values into macro variables. Second, pass the macro variables to the dataset. The codes are:

First, create macro variables.

proc sql; select procdate, prim,side,orgnname,orgnid,OrgnStTe into :procdate, :prim, :side, :orgnname, :orgnid, :OrgnStTe from ours where objid=783125; quit;

This step works well. Then pass the values.

data test; set m1; if id=184 then DO; objid=783125;procdate=&procdate.;prim=&prim.;side=&side.;orgnname=&orgnname.;orgnid=&orgnid.;OrgnStTe=&OrgnStTe.; END; run;

For this step, the error is about orgnname. Not quite sure about the error. I tried %bquote(&orgnname.) and %str(&orgnname.). Both were not working.

NOTE: Line generated by the macro variable "ORGNNAME". 1 CALVARY JOHN JAMES MEMORIAL HOSPITAL ---- 388 76 ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

最满意答案

展开宏变量时,生成的代码需要是有效的SAS语法。 在您想要引用字符串文字的情况下,该值必须在引号中。

ORGNNAME = "1 CALVARY JOHN JAMES MEMORIAL HOSPITAL";

因此,要使用宏变量,语法将如下所示:

ORGNNAME = "&ORGNAME";

但实际上,使用宏变量来传输已经存在于数据集中的值是没有意义的。 它需要太多的工作,容易出错或价值截断。 为什么不直接读取数据集中的数据?

data test; set m1; if id=184 then DO; set ours (where=(objid=783125) keep=objid procdate prim side orgnname orgnid OrgnStTe); end; run;

When you expand the macro variable the resulting code needs to be valid SAS syntax. In your case when you want to reference a string literal the value needs to be in quotes.

ORGNNAME = "1 CALVARY JOHN JAMES MEMORIAL HOSPITAL";

So to do that with your macro variables the syntax would look like:

ORGNNAME = "&ORGNAME";

But in reality using macro variables to transfer values that are already in data sets doesn't make sense. It requires too much work and is prone to errors or value truncation. Why not just read the data from the data set instead?

data test; set m1; if id=184 then DO; set ours (where=(objid=783125) keep=objid procdate prim side orgnname orgnid OrgnStTe); end; run;

更多推荐

本文发布于:2023-04-06 01:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/f89a50655b81f56b218821bf4ac2f53c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   正确   Macro   correctly   read

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!