dxystata 发表于 2014-11-22 10:11 
为什么在sql中用strip和compress函数无效呢?谢谢!
并不是strip或compress函数在sql中无效。
我觉得可能是因为SQL的处理规则。
SQL里的表就是由行和列组成的。列有各种属性,包括列宽(length)。
在SAS中SQL 的SELECT INTO创建宏变量的时候,SQL会把SELECT的内容当做一个一个变量来看待。
而且变量的长度也决定了INTO后宏变量的“长度”。比如变量长度是10, strip(之后的值只有3位,那做出的宏变量的值里就会有7个空格。
例如下面的例子,同时参考strip等函数的特点 If the STRIP function returns a value to a variable that has not yet been assigned a length, by default the variable length is determined by the length of the first argument.
proc sql noprint;
select name
,strip(" Alfred ")
,compress(" A lfred ")
,cats(" Alfred ")
into:name1, :name2, :name3, :name4 from sashelp.class;
quit;
%put *&name1*;
%put *&name2*;
%put *&name3*;
%put *&name4*;
%put %length(*&name1*);
%put %length(*&name2*);
%put %length(*&name3*);
%put %length(*&name4*);