英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论