SAS 数字到字符的转换? [英] SAS numeric to character conversion?

查看:95
本文介绍了SAS 数字到字符的转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们将数字转换为字符时,我们应该使用如下的数字格式

When we convert a numeric to character , we should use a numeric format like the following

data test ; 
prodID = 001 ;
result = put(prodID , 1.) ;
run ; 

proc print ;
run ; 

<小时>

我也尝试使用字符格式 $1. ,它也有效

data test ; 
prodID = 001 ;
result = put(prodID , $1.) ;   *I am using $1. here ; 
run ; 

proc print ;
run ; 

问题是为什么第二个代码有效?它不应该工作.我们应该使用数字或字符格式还是无关紧要?

推荐答案

您确实收到了第二个代码的警告:

You do get a warning with the second code:

警告:变量 prodID 已被定义为数字.

WARNING: Variable prodID has already been defined as numeric.

那是因为您将字符格式应用于数字变量但是 put 函数的结果是 always 字符.

That's because you are applying a character format to a numeric variable But the result of the put function is always character.

这篇关于SAS 数字到字符的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆