SAS - 使用 put() 和 input() 转换数据类型

使用 input () 还是 put() 转换变量数据类型取决于 source data type 和 target data type。对于 input() 和 put(),有四条原则:

  • PUT() always creates character variables
  • INPUT() can create character or numeric variables based on the informat
  • The source format must match the source variable type in PUT()
  • The source variable type for INPUT() must always be character variable

EXAMPLE :

Convert Raw to Returned Function Call Raw Type Raw Value

 Returned

Type

 Returned

Value

character variable to another character variable

A  PUT(name, $10.);char, char format‘Richard’char always‘Richard   ’
numeric variable to character variable with numeric valueB  PUT(age, 4.);num, num format30char always‘  30’
character variable to another character variable with a user defined formatC  PUT(name, $nickname.);char, char format‘Richard’char always‘Rick’
character variable with numeric value and informat to a numeric variableD  INPUT(agechar, 4.);char always‘30’num, num informat30
character variable with numeric value and informat to a character variableE  INPUT(agechar, $4.);char always‘30’char, char informat‘  30’
character variable with numeric value and informat to a numeric variableF  INPUT(cost,comma7.);char always‘100,541’num, num informat100541

版权声明:本文为gtx_tt原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。