码迷,mamicode.com
首页 > 其他好文 > 详细

SAS--字符数字转换

时间:2019-10-23 00:29:32      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:不同   一个   for   sas   var   NPU   汉字   run   shel   

*数字变字符;
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--字符数字转换

标签:不同   一个   for   sas   var   NPU   汉字   run   shel   

原文地址:https://www.cnblogs.com/super-yb/p/11723401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!