简体   繁体   English

SAS Proc SQL中的CONVERT语句

[英]CONVERT statement in SAS Proc SQL

I'm running the following code, which is supposed to compare two columns of a SAS dataset for me: 我正在运行以下代码,该代码应该为我比较SAS数据集的两列:

PROC SQL;

CREATE TABLE loandata.tv_curve AS
SELECT DISTINCT CONVERT(INT, srp_contract_lifetime) as srp_contract_lifetime, rpa_tv
FROM loandata.sas_f_risk_parameter_cn
WHERE rpa_tv IS NOT NULL
ORDER BY CONVERT(INT, srp_contract_lifetime);

QUIT;

However, when I run this code I get the following error messages: 但是,当我运行此代码时,出现以下错误消息:

ERROR: Function CONVERT could not be located.
ERROR: Function CONVERT could not be located.
ERROR: The following columns were not found in the contributing tables: INT.

How can I convert my srp_contract_lifetime variable into an int correctly? 如何将srp_contract_lifetime变量正确转换为int?

CONVERT is a TSQL (Microsoft SQL Server) function, not a function. CONVERT是TSQL(Microsoft SQL Server)函数,而不是函数。 In SAS you do conversions using input and put . 在SAS中,您可以使用inputput进行转换。

PROC SQL;

CREATE TABLE loandata.tv_curve AS
SELECT DISTINCT input(srp_contract_lifetime,12.) as srp_contract_lifetime, rpa_tv
FROM loandata.sas_f_risk_parameter_cn
WHERE rpa_tv IS NOT NULL
ORDER BY input(srp_contract_lifetime,12.);

QUIT;

As Gordon notes, this may not even be needed, as SAS only has numeric and character. 正如Gordon指出的那样,甚至可能不需要这样做,因为SAS仅具有数字和字符。 Only use the input if it's stored as character; 仅当input存储为字符时才使用; otherwise remove it. 否则将其删除。

SAS only has numbers (floating point) and fixed length character strings. SAS只有数字(浮点数)和固定长度的字符串。

If your variable is a number and it only has integer values then there is nothing to convert. 如果您的变量是数字,并且只有整数,则没有任何可转换的内容。 If you want to remove the fractional part you could use INT(), FLOOR(), CIEL() or ROUND() functions depending on how you want to do the conversion. 如果要删除小数部分,可以根据要执行的转换方式使用INT(),FLOOR(),CIEL()或ROUND()函数。

If your variable is a character string then you could use either the INPUT() or INPUTN() function. 如果变量是字符串,则可以使用INPUT()或INPUTN()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM