全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
6934 5
2016-04-27
Given the SAS data set SASUSER.HIGHWAY:

  Steering Seatbelt Speed Status  Count
  ——– ——– —– ——- —–
  absent   No       0-29  serious    31
  absent   No       0-29  not      1419
  absent   No       30-49 serious   191
  absent   no       30-49 not      2004
  absent   no       50+   serious   216

  The following SAS program is submitted:

  %macro HIGHWAY(Belt=no);     
     proc print data=SASUSER.HIGHWAY;   
        where Seatbelt=\”&Belt\” ;
     run;   
  %mend;     

  %HIGHWAY(Belt=No)   

  How many observations appear in
  the generated report?
A.
0   

B.
2   

C.
3   

D.
5
为什么答案是C 啊,不应该是B 么?


而且运行上段程序在SAS里,显示错误,这是为什么?


1       proc print data=crackman;         where Seatbelt=\"&Belt"\;      run;

                                                         -

                                                         22

                                                         76

ERROR: 解析 WHERE 子句时出现语法错误。


ERROR 22-322: 语法错误,期望下列之一: 名称, 带引号的字符串, 数值常数, 日期时间常数, 缺失值, (, *,

              +, -, :, INPUT, NOT, PUT, ^, ~.


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


二维码

扫码加我 拉你入群

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

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

全部回复
2016-4-28 00:33:40
第一句话赋给belt的no是初始值,一旦最后一句调用程序时赋予了belt新的值No,将会覆盖初始值。
ps:如果这时第一句用%let定义了全局变量,则以%let赋的值具有最高优先执行权,具体优先执行规则如下:
%let语句中赋的值〉调用程序时赋的值〉程序开始时赋的初始值
二维码

扫码加我 拉你入群

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

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

2016-4-28 04:20:30
dingding
二维码

扫码加我 拉你入群

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

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

2016-4-28 09:29:21
问一下这里的\是起什么作用的?
二维码

扫码加我 拉你入群

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

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

2016-4-28 13:19:15
%HIGHWAY(Belt=No)    -----------------  调用的时候赋了值 No,所以答案是 3 条吧。

/    是转义字符 , 所以这个语句 相当于  where Seatbelt=\”&Belt\” ; 相当于 ------------>  where Seatbelt=*No* ;这个条件。

For example, if the variable X contains the values abc, a_b, and axb, the following LIKE operator with an escape character selects only the value a_b. The escape character (/) specifies that the pattern searches for a literal ' _' that is surrounded by the characters a and b. The escape character (/) is not part of the search.

where x like 'a/_b' escape '/';

Without an escape character, the following LIKE operator would select the values a_b and axb. The special character underscore in the search pattern matches any single b character, including the value with the underscore:


where x like 'a_b';
二维码

扫码加我 拉你入群

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

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

2016-4-28 20:18:53
Pennsy 发表于 2016-4-28 00:33
第一句话赋给belt的no是初始值,一旦最后一句调用程序时赋予了belt新的值No,将会覆盖初始值。
ps:如果这 ...
谢谢!!!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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