楼主: 啦啦噜啦啦
5038 4

[学习分享] SAS BASE 第十题 [推广有奖]

  • 0关注
  • 1粉丝

已卖:130份资源

大专生

45%

还不是VIP/贵宾

-

威望
0
论坛币
102 个
通用积分
3.9200
学术水平
10 点
热心指数
10 点
信用等级
9 点
经验
599 点
帖子
61
精华
0
在线时间
27 小时
注册时间
2012-10-27
最后登录
2024-3-21

楼主
啦啦噜啦啦 学生认证  发表于 2015-8-7 23:27:54 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

10. The following SAS program issubmitted:
data WORK.RETAIL;
   Cost=‘$20,000′;
   Discount=.10*Cost;
run;
What is the result?

     A. Thevalue of the variable Discount in the output data set is 2000.No messages arewritten to the SAS log.
     B. The value of the variable Discount in the outputdata set is 2000.A note that conversion has taken place is written to the SASlog.
     C. The value of the variable Discount in the outputdata set is missing. A note in the SAS log refers to invalid numeric data.
     D. The variable Discount in the output data set is setto zero.No messages are written to the SAS log.

这个题非常地狡猾~

【相关知识点】numeric -character 以及 character - numeric variable 的自动转化

【答案】C

【解释】正常情况下,numeric character variable是可以相互自动转化的;但是当SAS 试图把character 换成numeric的时候,$ 阻止了这一进程。

【同类题对比】

The following SAS program is submitted:
data work.retail;
cost = '20000';
total = .10 * cost;
run;
Which one of the following is the value of thevariable TOTAL in the output data set?
A. 2000
B. '2000'
C. . (missing numeric value)
D. ' ' (missing character value)

【答案】A 这里并没有$SAS 于是自己进行了自动转化

【模拟程序】

1)没有$-变了!

data test;

a=200;

b='abc';

b=a;

run;

proc print;

run;

2)有$-木有变

data test;

a='$200';

b=10*a;

run;

proc print;

run;

【补充知识】numericcharacter 的相生相爱

l Character – numeric 自动转换

1. Character– numeric 自动转换的条件

当这个charactervariable

1)被分配给一个本来被定义为numericvariable

2)被用在一个计算式子中 (如上面的同类题对比)

3)和一个number variable相比较的时候

  Eg: if height >= weight;

4) 被用在一个需要numeric variable 的方程式子中

Eg:age=sum(weight,height)

2. Theautomatic conversion

1)使用 w.d 形式

2)将会生成一个numeric性质的missingvalue,如果这个character variable 没有使用numeric的标准标记法

  

Character
  Value

  
  

automatic
  conversion

  
  

Numeric
  Value

  
  

12.47

  
  

=>

  
  

12.47

  
  

-8.96

  
  

=>

  
  

-8.96

  
  

1.243E1

  
  

=>

  
  

12.43

  
  

1,742.64

  
  

=>

  
  

.

  

3. 特殊情况

Where statement”不会帮你自动转换,因为他傻

4. 因为麻烦或者各种意想不到的情况可能发生,还是乖乖非自动转化的方程吧!

Input(source, informat) -> source 指的是the charactervariable

Eg: Salary=input(payrate,2.)*hours;

l Numeric - Character 自动转换

1. 自动转化的条件:

当这个 numericcharacter被:

1被分配给一个本来被定义为character variable

2)被用在一个需要character variableoperator

3)被用在一个需要character variable function

   Eg: Region=substr(site,1,4);

2. 手动转化

Put(source,format) -> source代表需要被转化的numericvariable,常数,或者表达式。


二维码

扫码加我 拉你入群

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

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

关键词:SAS base Base conversion Character following SAS SAS实例精选 初学sas

沙发
smilysophia 学生认证  发表于 2015-8-9 08:54:28
谢谢讲解

藤椅
仙风云体 发表于 2015-8-12 08:33:03
楼主做的转换表不错,赞一个

板凳
sophie262 发表于 2016-7-17 15:47:50
学到了 谢谢楼主的讲解

报纸
chikongling 发表于 2018-10-15 07:52:29
哇!!超级谢谢!!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-3 06:41