楼主: dxystata
3304 14

如何使数据集中变量保留最大长度。 [推广有奖]

11
dxystata 发表于 2013-12-19 06:23:35
farmman60 发表于 2013-12-17 10:23
proc sql;
  select count(name) into: num from (select name,type from dictionary.columns where lib ...
程序有WARNING

WARNING: 输入数据集为变量“x”指定了多个长度。这可能会造成数据截断。
WARNING: 输入数据集为变量“y”指定了多个长度。这可能会造成数据截断。

12
farmman60 发表于 2013-12-19 09:22:08
dxystata 发表于 2013-12-19 06:23
程序有WARNING

WARNING: 输入数据集为变量“x”指定了多个长度。这可能会造成数据截断。
It is normal warning, just like merge or update, two datasets with same name but different length.

It is sure to use shorter lengths than that in dataset so it is Ok.

http://support.sas.com/documenta ... ln17krhgsbupntq.htm

13
dxystata 发表于 2013-12-19 09:30:32
farmman60 发表于 2013-12-19 09:22
It is normal warning, just like merge or update, two datasets with same name but different length. ...
从编程角度,出现warning是不恰当的!

14
farmman60 发表于 2013-12-19 09:45:55
dxystata 发表于 2013-12-19 09:30
从编程角度,出现warning是不恰当的!
Good point.

data a;
set a;
length &length_change;
run;

15
bobguy 发表于 2013-12-20 10:58:04
You have to read the data in twice, one for measuring the proper length for variables, the other for defining the correct length for variables. Here is a simple way,

data _null_;
retain lenx leny;
length x $200 y $200;
infile cards eof=eof;
input x y;
lenx=max(1,length(x));
leny=max(1,length(y));
return;
eof:
call symputx('lenx', catt('$',lenx));
call symputx('leny', catt('$',leny));
cards;
a b
aaa bbbbbbbbbbbbbbbbbb
;

%put &lenx  &leny;

data tmp;

length x &lenx y &leny;
infile cards ;
input x y;
cards;
a b
aaa bbbbbbbbbbbbbbbbbb
;

proc contents data=tmp;
run;

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-19 09:03