SAS--字符数字转换
Posted super-yb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAS--字符数字转换相关的知识,希望对你有一定的参考价值。
*数字变字符; data class; set sashelp.class(rename= (age=c_age height=c_height weight=c_weight) ); age=put(c_age,$8.); *c_age相当于原来的age,是数字型的,给c_age一个新的格式; height=put(c_height,$8.); weight=put(c_weight,$8.); drop c_:; *字符偏右,数字型偏左,c_: 省去多个变量名的书写; run; proc print data=class; run; *字符变不同format的字符; data class1; set sashelp.class; name=put(name,$4.); *一个汉字两个字符,所以只剩前两个字; run; proc print data=class1; run; proc means data=class; *查看log; var age height weight; run; *字符变数字; data class2 ; set class(rename= (age=c_age height=c_height weight=c_weight) ); age=input(c_age,best8.); height=input(c_height,best8.); weight=input(c_weight,best8.); drop c_:; run; proc means data=class2; *查看log; var age height weight; run; *字符变数字2; data class3; set class(rename= (age=c_age height=c_height weight=c_weight) ); age=c_age+0; height=c_height*1; weight=c_weight+0; drop c_:; run; proc means data=class3; *查看log; var age height weight; run;
以上是关于SAS--字符数字转换的主要内容,如果未能解决你的问题,请参考以下文章