使用 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 variables

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 value B  PUT(age, 4.); num, num format 30 char always ‘  30’
character variable to another character variable with a user defined format C  PUT(name, $nickname.); char, char format ‘Richard’ char always ‘Rick’
character variable with numeric value and informat to a numeric variable D  INPUT(agechar, 4.); char always ‘30’ num, num informat 30
character variable with numeric value and informat to a character variable E  INPUT(agechar, $4.); char always ‘30’ char, char informat ‘  30’
character variable with numeric value and informat to a numeric variable F  INPUT(cost,comma7.); char always ‘100,541’ num, num informat 100541
posted on 2022-03-18 18:31  MOZY  阅读(687)  评论(0编辑  收藏  举报