• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在SAS文本转换为数字格式

用户头像
it1352
帮助5

问题说明

我有一个来自数据仓库的大数据集,其中一个变量已作为字符串读入.该变量只包含数字,我没有得到原始数据,所以我自己无法读入数据.

I have a big dataset from a data warehouse where one of the varibels have been read in as a string. The variable only contains numbers and I havn't got the raw data so I can't read in the data myself.

示例:

Variabel
4659721685425645
1234564578978896
7894567894567894

格式为 20 美元.并且信息是 19 美元.

The format is $20. and the informat is $19.

我想将它转换为数字,以便我可以将数据集与另一个数据集连接起来,在同一个变量上,但这个变量是数字.

I want to convert it into numeric so I can join the dataset with another dataset, on the same variable, but where this variable is numeric.

我已经试过了:

 data x_numeric;
        set x;
        format variable 20.;
 run;

感谢帮助!

正确答案

#1

一个 20 位数字不能在 SAS 中以全精度数字存储.SAS 使用双精度浮点数,这意味着它们以 8 个字节存储数字.52 位用于尾数(精度),11 位用于指数,1 位用于符号.2^53 是 SAS 中可以精确存储的最大数字,大约为 9x10^15(任何 15 位数字,大多数为 16 位数字).这适用于符合 IEEE 标准的系统(基于 Intel、Unix、Windows 等);IBM 大型机使用 56 位作为尾数,因此最多可以精确存储 2^57.

A 20 digit number cannot be stored numerically in SAS with full precision. SAS uses double precision floating point numbers, meaning they store the number in 8 bytes. 52 bits are used for the mantissa (the precision), 11 for the exponent, and 1 for the sign. 2^53 is the largest number that could be stored precisely in SAS, or about 9x10^15 (any number of 15 digits, and most numbers of 16 digits). This is true on IEEE-compliant systems (Intel-based, so Unix, Windows, etc.); IBM mainframes use 56 bits for the mantissa, so up to 2^57 can be stored precisely.

请参阅 SAS 文章关于数字精度了解更多详情.

See the SAS article on numeric precision for more details.

如果您的数字可以安全地用数字表示(即小于 9E16),那么您可以使用 input 进行转换.

If your number can be safely represented numerically (ie, is less than 9E16), then you can convert it using input.

var_n = input(var_c, 20.);

其中 20. 是读取它的信息(应该与字符变量的 format 宽度相同,而不是它的信息).您不必在数据集中永久执行此操作;如果您使用的是 sql join,您可以使用 on tbl1.var = input(tbl2.var,20.) 或类似方法(尽管在数据步骤中合并您不能那样做).

Where 20. is the informat to read it in with (should be same width as the format of the character variable, not its informat). You don't have to do this in the dataset permanently; if you're using sql join you can just join using on tbl1.var = input(tbl2.var,20.) or similar (though in a data step merge you couldn't do that).

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcbabje
系列文章
更多 icon
同类精品
更多 icon
继续加载