全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1506 2
2020-12-30
第一个问题:我选A,模考给的答案是C。给name设置长度的语句是最先出现的,为什么选C呢?
The variable Name in the data set Employee has a $CHAR10 format. The variable Name in the data set Sales has a $CHAR15 format.
The following SAS program is submitted.
data both;
         length name$ 20;
         merge sales employee;
        by id;
run;
What is the format for the variable Name in the data set Both?
A)        $20
B)        $CHAR10
C)        $CHAR15
D)        $CHAR20

第二个问题

Suppose you need to create the variable FullName by concatenating the values of
FirstName, which contains first names, and LastName, which contains last names.
What is the best way to remove extra blanks between first names and last names?
a. data work.maillist;
set cert.maillist;
length FullName $ 40;
fullname=trim firstname||' '||lastname;
run;
b. data work.maillist;
set cert.maillist;
length FullName $ 40;
fullname=trim(firstname)||' '||lastname;
run;
c. data work.maillist;
set cert.maillist;
length FullName $ 40;
fullname=trim(firstname)||' '||trim(lastname);
run;
d. data work.maillist;
set cert.maillist;
length FullName $ 40;
fullname=trim(firstname||' '||lastname);

我选C,答案是B。求问各位大佬答案给的解释里的最后一句话该如何理解? 先谢谢啦!
The TRIM function removes trailing blanks from character values. In this case, extra
blanks must be removed from the values of FirstName. Although answer c also
works, the extra TRIM function for the variable LastName is unnecessary. Because
of the LENGTH statement, all values of FullName are padded to 40 characters.
二维码

扫码加我 拉你入群

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

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

全部回复
2021-1-14 21:12:27
你这个太难阅读了,能不能排下版啊楼主
二维码

扫码加我 拉你入群

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

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

2021-2-26 10:48:27
第一题。Merge 后 name 长度为20。真实考试中不会用这种有错误答案的题。
代码如下:
复制代码

第二题,答案C没有错。但是选答案B更好。(其实这题考试不会出现,没什么意义)
注意,原始数据中,Firstname 和 Lastname 的长度是40 (或者任何长度,没区别),
sas 对待不够长的字符的处理方式是,强行填充为规定长度。
举例: FirstName 的长度为10,那么看起来是"John"的字符串实际上是"John      "
同理,LastName 的长度为10,那么看起来是"Smith"的字符串实际上是"Smith     "
如果我们想要"John Smith" ,那么不需要strip(Lastname) ,因为就算strip了,SAS也会把"John Smith" 强行填充为 "John Smith        "
这道题默认为LastName的数据中不出现开头为空格的情况。不然C是对的。工作中也是用C,因为我们不信任原始数据
另外,下次提问请排版,请respect 要回答你问题的人
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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