将值从字符转换为数字或从数字转换为字符
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将值从字符转换为数字或从数字转换为字符相关的知识,希望对你有一定的参考价值。
Original Source from http://support.sas.com/kb/24/590.html
/* Convert a character value to a numeric value by using the INPUT */ /* function. Specify a numeric informat that best describes how to */ /* read the data value into the numeric variable. */ /* */ /* When changing types a new variable name is required. If you need */ /* to keep the original variable name for the new type, use the */ /* RENAME= option as illustrated in Sample 2. */ data char; input string :$8. date :$6.; numeric=input(string,8.); sasdate=input(date,mmddyy6.); format sasdate mmddyy10.; datalines; 1234.56 031704 3920 123104 ; proc print; run; /* Convert a numeric value to a character value by using the PUT */ /* function. Specify a numeric format that describes how to write */ /* the numeric value to the character variable. To left align */ /* the resulting character value, specify -L after the format */ /* specification. */ /* */ /* When changing types a new variable name is required. If you need */ /* to keep the original variable name, use the RENAME= option on */ /* the SET statement to rename the variable as it comes into the PDV. */ /* This allows the original variable name to be reused when you */ /* change type. */ data now_num; input num date: mmddyy6.; datalines; 123456 110204 1000 120504 ; data now_char; set now_num (rename=(num=oldnum date=olddate)); num=put(oldnum,6. -L); date=put(olddate,date9.); run; proc print; run;
以上是关于将值从字符转换为数字或从数字转换为字符的主要内容,如果未能解决你的问题,请参考以下文章