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

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

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中:

年份 X 毛利 净利
2008 1 (18.13%) (19.3%)
2009 1 25.50% 23.8%
2010 1 8.55% 7.0%
2011 1 (6.42%) (7.7%)

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

年份 X 毛利 净利
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;

但在处理大量小数时不考虑精度和小数点问题。

链接

英文:

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-2.html
匿名

发表评论

匿名网友

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

确定