如何在SAS中将百分比转换为实数?

huangapple go评论110阅读模式
英文:

How to convert percents to real number in SAS?

问题

这是我用来从Excel文件导入数据的SAS代码。
Excel文件不属于我,所以我无法更改文件中的数据外观:

Proc Import Out = Net_Yields
Datafile = "File.xlsx"
dbms = xlsx
replace;
Getnames = YES;
Sheet = "Gtee Vector";
Range = "S5:V45";
Run;

我从Excel导入数据,它以以下格式出现在SAS中:

Years X Gross Net
2008 1 (18.13%) (19.3%)
2009 1 25.50% 23.8%
2010 1 8.55% 7.0%
2011 1 ( 6.42%) ( 7.7%)

我正在处理非常大的数字,所以小数点后的每个小数位都很重要。
我需要将百分比转换为实数格式,使其看起来像这样:

Years X Gross Net
2008 1 -0.1812793769191860 -0.1925832119518600
2009 1 0.2550005600450760 0.2376731361391290
2010 1 0.0854571645604569 0.0704705764896025
2011 1 -0.0641682597261736 -0.0770890135366603

我尝试过格式化数据,但最好的结果是小数点后5位。
非常感谢您的帮助。提前致谢。

英文:

This is the SAS code I use to import data from excel file.
The excel file doesn't belong to me so i can't change data appearance within the file:

Proc Import Out = Net_Yields
Datafile = "File.xlsx"
dbms = xlsx
replace;
Getnames = YES;
Sheet = "Gtee Vector";
Range = "S5:V45";
Run;

I import data from excel and it comes to SAS in this format:

Years X Gross Net
2008 1 (18.13%) (19.3%)
2009 1 25.50% 23.8%
2010 1 8.55% 7.0%
2011 1 ( 6.42%) ( 7.7%)

I'm working with very large numbers so every decimals after decimal point make sense and is very important.
I need to convert the percents to real numbers format so it will look like this:

Years X Gross Net
2008 1 -0.1812793769191860 -0.1925832119518600
2009 1 0.2550005600450760 0.2376731361391290
2010 1 0.0854571645604569 0.0704705764896025
2011 1 -0.0641682597261736 -0.0770890135366603

I tried to format the data but the best result I could get is 5 digits after the decimal point.
Any help appreciated.
Thanks in advance.

答案1

得分: 1

使用格式控制小数位数。n.p.中的“n”表示列数,“p”表示小数点后的位数。

data have;
percent=-0.1812793769191860;
format percent percent9.2;
run;

data want;
set have;
format percent 20.15;
run;

但在处理大量小数时,不考虑精度和小数位数。

https://www.sfu.ca/sasdoc/sashtml/lrcon/z0695157.htm

英文:

Use the format to control numer of decimals. n.p. "n" number of columns with "p" decimal points.

data have;
percent=-0.1812793769191860;
format percent percent9.2;
run;

data want;
set have;
format percent 20.15;
run;

But not the precision and decimal considerations when working with at large number of decimals

https://www.sfu.ca/sasdoc/sashtml/lrcon/z0695157.htm

huangapple
  • 本文由 发表于 2023年8月9日 14:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定