我正在尝试评估PROC SQL中的变量是字符还是数字。然后,这将确定要使用哪个WHERE子句。我以为使用VTYPE会给我想要的结果,但听起来你不能在PROC SQL中使用该功能。是否有一个特定的函数可以在PROC SQL中使用,它将返回变量类型并在if语句中进行求值?如何将该函数合并到SQL代码中?
我的完整代码如下:
%MACRO miss_count(vars=,dataset=,business_line=);
PROC SQL;
SELECT s1.&vars, s1.year AS years,
COUNT(*) AS missing,
(SELECT COUNT(*) FROM saslib.&dataset AS s2 WHERE s2.year=s1.year) AS total,
(COUNT(*)/(SELECT COUNT(*) FROM saslib.&dataset AS s3 WHERE s3.year=s1.year))*100 AS perc_missing
FROM saslib.&dataset AS s1
%IF VTYPE(&vars) = 'C' %THEN WHERE s1.&vars IN (' ', 'UNKN', 'NONE') %ELSE WHERE s1.&vars IN (.)
AND s1.bus_line = &business_line
GROUP BY s1.&vars, s1.year;
QUIT;
%MEND miss_count;
%miss_count(vars=cpt_typcode, dataset=sample, business_line='COM')
然而,当我运行此代码时,我收到错误:
ERROR: Required operator not found in expression: VTYPE(&vars) = 'C'
ERROR: The macro MISS_COUNT will stop executing.
我是SAS的新手,我想知道如何在PROC SQL中评估变量是字符还是数字。
有关详细信息,请参见下面的输出。
MLOGIC(MISS_COUNT): Beginning execution.
MLOGIC(MISS_COUNT): Parameter VARS has value cpt_typcode
MLOGIC(MISS_COUNT): Parameter DATASET has value sample
MLOGIC(MISS_COUNT): Parameter BUSINESS_LINE has value 'COM'
MPRINT(MISS_COUNT): PROC SQL;
ERROR: Required operator not found in expression: VTYPE(&vars) = 'C'
ERROR: The macro MISS_COUNT will stop executing.
MPRINT(MISS_COUNT): SELECT s1.cpt_typcode, s1.year AS years, COUNT(*) AS missing, (SELECT COUNT(*) FROM saslib.sample AS s2 WHERE
s2.year=s1.year) AS total, (COUNT(*)/(SELECT COUNT(*) FROM saslib.sample AS s3 WHERE s3.year=s1.year))*100 AS perc_missing FROM
saslib.sample AS s1
MLOGIC(MISS_COUNT): Ending execution.