楼主: dxystata
5486 11

输出格式名无效 [推广有奖]

11
dxystata 发表于 2014-11-22 10:11:22
pobel 发表于 2014-11-17 16:15
1. 首先,如果SELECT出的值前后有空格,SQL INTO创建宏变量过程中不会去掉前后的空格。
2. (猜测)用SQ ...
为什么在sql中用strip和compress函数无效呢?谢谢!

12
pobel 在职认证  发表于 2014-11-22 10:43:44
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*);

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 03:40