hehekaixin 发表于 2011-3-31 10:34 
cadlag的解答完全正确。
以下code复制到editor中即可:
data a;
length x12 $ 50;
set a;
format x12 $50.;
if _n_=128 then delete;
run;
X12原来的值不会被删掉,因为length语句只是设定变量长度,而$50比原来的$20要长;
至于format语句是控制变量的显示格式,也要相应改成$50.。
还是不行,这次我吧完整的结果贴出来,请大家看一下问题在哪里?
命令如下:
data peter;
length x y z $20;
input x y z;
cards;
a b c
e f g
h i j
;
run;
data _null_;
set peter;
put _all_;
run;
data peter;
length x $50;
run;
set peter;
format x $50;
if _n_=3 then delete;
run;
sas的log结果如下:
82 data peter;
83 length x y z $20;
84 input x y z;
85 cards;
NOTE: The data set WORK.PETER has 3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
89 ;
90 run;
91 data _null_;
92 set peter;
93 put _all_;
94 run;
x=a y=b z=c _ERROR_=0 _N_=1
x=e y=f z=g _ERROR_=0 _N_=2
x=h y=i z=j _ERROR_=0 _N_=3
NOTE: There were 3 observations read from the data set WORK.PETER.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
95 data peter;
96 length x $50;
97 run;
NOTE: Variable x is uninitialized.
NOTE: The data set WORK.PETER has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
98 set peter;
---
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
99 format x $50;
------
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
100 if _n_=3 then delete;
--
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
101 run;