全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3386 10
2013-03-02
悬赏 388 个论坛币 已解决
data a;
input x $19.;
cards;
取"+"前面的数据
;
run;

%macro sh(note);
data b;
y="&note";
run;
%mend;

%sh(%nrbquote(取"+"前的数据));

data _null_;
set a;
call execute(%nrstr("%sh(")||%nrbquote(x)||%str(")"));
run;

上述代码,直接引用宏%sh可以运行成功,而用call execute则提示有问题
想问一下为什么,上面两个调用宏的代码不应该是完全一样的吗?
求高手悬赏388币之后,我再加100币,望高手相助,急!!!


最佳答案

pobel 查看完整内容

data a; input x $19.; cards; a"+"aaaaa c'+'cccc haha"+"hahaha ; run; %macro sh(note); data b; y="¬e"; run; %mend; data _null_; set a; call execute('%nrstr(%sh('||'%bquote('||strip(x)||")))"); run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-3-2 22:44:20
data a;
input x $19.;
cards;
a"+"aaaaa
c'+'cccc
haha"+"hahaha
;
run;

%macro sh(note);
data b;
y="&note";
run;
%mend;

data _null_;
set a;
call execute('%nrstr(%sh('||'%bquote('||strip(x)||")))");
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-3 11:17:27
data a;
input x $19.;
cards;
A"+"B
;
run;

%macro sh(note);
data b;
y="&note";              /* the y hold character string */
put "y= " y;
run;
%mend;

%sh(%nrbquote(A"+"B));  
                                          /* OK ,    output: y = A"+"B  */
%sh( A);                   /*  OK,   output:  y = A  */
%sh(A"+"B);             /* error, Character values have been converted to numeric values */
                    /* reason:  the left " in %sh() was combine with the first " in %sh(A"+"B) and
                                     the right " in %sh() was combined with the second " in %sh(A"+"B) to produce
                                    "A"+"B" this caused the error since y want a character string   */         
%sh(A+B);           /*   OK,    output: y = A+B */
%sh(A+"B");        /* error:    Character values have been converted to numeric values */

data _null_;
set a;
* call execute(  '%sh(A"+"B)' );                        /* error: data b; y="A"+"B"; */
* call execute(  '%sh(%nrbquote(A"+"B))');     /* data b; y="A" + "B"; */
call execute(  '%sh(A+B)'  );                              /* OK  output: y=A+B */
run;              /* NOTE use single quotation around the macro %sh(A+B) */

From the log message, it seems that the quotation mark inside macro (ie.  Y=”&note”) were mixed up with the quotation mark in the CALL EXECUTE statement.
This is because the macro variable in CALL EXECUTE statement was resolved immediately.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-3 11:34:25
个人认为这个问题的关键有两个地方:
1. 要使call execute中对宏的引用在数据步执行过程中执行;
2. 要使%bquote也作为宏引用中的一部分。也就是说%bquote要加引号使其作为字符串。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-3 11:46:37
这太深了,不懂。学习下
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-3 12:05:46
pobel 发表于 2013-3-3 11:34
个人认为这个问题的关键有两个地方:
1. 要使call execute中对宏的引用在数据步执行过程中执行;
2. 要使 ...
看来我对宏的理解是白学了。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群