任何人都可以向我解释如何让 PROC SQL 为自定义函数的结果提供我在函数定义中指定的长度吗? Datastep 做得很好,但 SQL 给了我 200 个字符的默认长度。
以下代码演示了该问题:
proc fcmp outlib = work.funcs.funcs ;
* Note type/length specification ;
function testy(istr $) $11 ;
return ('bibbitybobb') ;
endsub ;
quit ;
options cmplib = work.funcs ;
data from_dstep ;
set sashelp.class ;
tes = testy(name) ;
run ;
proc sql ;
create table from_sql as
select *
, testy(name) as tes
from sashelp.class
;
describe table from_dstep ;
describe table from_sql ;
quit ;
我的登录是:
47 describe table from_dstep ;
NOTE: SQL table WORK.FROM_DSTEP was created like:
create table WORK.FROM_DSTEP( bufsize=65536 )
(
Name char(8),
Sex char(1),
Age num,
Height num,
Weight num,
tes char(11)
);
48 describe table from_sql ;
NOTE: SQL table WORK.FROM_SQL was created like:
create table WORK.FROM_SQL( bufsize=65536 )
(
Name char(8),
Sex char(1),
Age num,
Height num,
Weight num,
tes char(200)
);
如您所见,datastep 为我的“tes”变量提供了 11 的长度,但 sql 为我提供了 200。
使用 SQL 时有没有办法获得长度 11?
最佳答案
不幸的是,我不这么认为。 SQL 和数据步骤在这方面的工作方式不同,其他内置函数也有一些相同的问题(例如,CATS/CATX 在 SQL 中的默认值与数据步骤中的默认值不同)。我认为这与数据步骤中的编译方式与 SQL 中的解释方式有关。我相信我已经看到了一些指定这是预期行为的内容,但我现在似乎找不到它;如果您想要更多详细信息,但这里没有其他人可以提供,也许可以使用 SAS support 开始一个轨道。看看他们怎么说。
当然可以直接在SQL中设置:
proc sql ;
create table from_sql as
select *
, testy(name) as tes length 11
from sashelp.class
;
quit;
关于sas - sql 不尊重我的 fcmp 函数长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45871268/