如何在SAS中将文本转换为数字格式 [英] How to convert text to numeric format in SAS

查看:315
本文介绍了如何在SAS中将文本转换为数字格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

感谢帮助!

推荐答案

一个 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).

这篇关于如何在SAS中将文本转换为数字格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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