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