楼主: Imasasor
3460 10

请教一个call execute和宏引用的问题 [推广有奖]

  • 1关注
  • 64粉丝

VIP

已卖:215份资源

学科带头人

33%

还不是VIP/贵宾

-

TA的文库  其他...

超哥喜欢的文章

威望
1
论坛币
47033 个
通用积分
3.1376
学术水平
238 点
热心指数
246 点
信用等级
231 点
经验
37132 点
帖子
849
精华
3
在线时间
2235 小时
注册时间
2012-7-4
最后登录
2024-10-10

初级学术勋章 初级热心勋章 初级信用勋章 中级热心勋章 中级学术勋章

楼主
Imasasor 发表于 2013-3-2 22:44:19 |AI写论文
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;
关键词:EXECUTE Cute call cut ECU null

本帖被以下文库推荐

欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

沙发
pobel 在职认证  发表于 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;
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 100 + 100 + 5 + 5 + 5 精彩帖子,确实解决了问题
webgu + 3 + 3 + 3 精彩帖子

总评分: 经验 + 100  论坛币 + 100  学术水平 + 8  热心指数 + 8  信用等级 + 8   查看全部评分

和谐拯救危机

藤椅
yongyitian 发表于 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.
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Imasasor + 80 + 80 + 2 + 2 + 2 精彩帖子

总评分: 经验 + 80  论坛币 + 80  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

板凳
pobel 在职认证  发表于 2013-3-3 11:34:25
个人认为这个问题的关键有两个地方:
1. 要使call execute中对宏的引用在数据步执行过程中执行;
2. 要使%bquote也作为宏引用中的一部分。也就是说%bquote要加引号使其作为字符串。
和谐拯救危机

报纸
respringwa 发表于 2013-3-3 11:46:37
这太深了,不懂。学习下

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

7
Imasasor 发表于 2013-3-3 12:27:26
pobel 发表于 2013-3-3 11:34
个人认为这个问题的关键有两个地方:
1. 要使call execute中对宏的引用在数据步执行过程中执行;
2. 要使 ...
代码确实可用,不过还是没有很好的理解,有时间再好好研究一下
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

8
Imasasor 发表于 2013-3-3 12:28:35
yongyitian 发表于 2013-3-3 11:17
data a;
input x $19.;
cards;
你说的这些我也发现了,可是还是没有能很好地解决问题
欢迎加入亚太地区第一R&Python数据挖掘群: 251548215;

9
yongyitian 发表于 2013-3-3 12:33:09
pobel 发表于 2013-3-2 22:44
data a;
input x $19.;
cards;
大侠能不能把这些 '' || ||''讲详细点

10
pobel 在职认证  发表于 2013-3-3 13:59:55
yongyitian 发表于 2013-3-3 12:33
大侠能不能把这些 '' || ||''讲详细点
||只是连接字符串的符号。
几个字符串通过||连接到一起后再作为call execute()的参数去执行
和谐拯救危机

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 21:56