全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3751 5
2013-07-24
85. Given the SAS data set OURDATA:
OURDATAObsproduct sales
1 OR 1000
2 NE 1200
3 MM 1450
After submitting a SAS program, the following is written to the SAS log:
70 %macro a;
71 data _null_;
72 set ourdata;
73 call symput('product'!!left(_n_), product);
74 run;
75 %if &product1 = OR %then %do;
76 proc means data = ourdata;
77 run;
78 %end;
79 %mend;
80 %a
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
73:66
NOTE: There were 3 observations read from the data set WORK.OURDATA.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is
required. The condition was: &product1=OR
ERROR: The macro A will stop executing.
Which statement replaces the code in line 75 to successfully complete the program?
A.%if &product1 = %bquote(OR) %then %do;
B.%if %bquote(&product1) = OR %then %do;
C.%if %bquote(&product1 = OR) %then %do;
D.%if %bquote(&product1) = %bquote(OR) %then %do;

答案为什么是D?
当 product1 变成 OR 的时候问什么不能直接用 %if &product1 = OR 而要用 %bquote呢?

谢谢各位了

二维码

扫码加我 拉你入群

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

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

全部回复
2013-7-24 23:46:22
因为OR是SAS保留的关键字,代表逻辑“或”,所以必须quote
参见:Summary of Macro Quoting Functions and the Characters They Mask
二维码

扫码加我 拉你入群

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

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

2013-7-25 08:06:19
多谢!
二维码

扫码加我 拉你入群

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

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

2015-6-23 11:12:02
那为什么不能选A
二维码

扫码加我 拉你入群

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

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

2015-6-23 15:46:10
iceiiy 发表于 2015-6-23 11:12
那为什么不能选A
因为程序执行时 左边的&product1解析成OR  此时左边的OR是没有经过quoting的 因此sas还是把他当成一个关键词  所以左右的OR都得需要经过bquote的quoting
二维码

扫码加我 拉你入群

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

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

2018-2-20 22:34:49
厉害!!受教了
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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