标题: 导入excel2000数据后字符变量长度问题 [打印本页] 作者: shiyiming 时间: 2003-10-22 23:07 标题: 导入excel2000数据后字符变量长度问题 I am new. I have a problem. Please help.
When I import excel2000 data file to SAS using Import Wizard, then use proc contents to check data struction. I got that all character variable's length is 255. what is the problem. Can anybody tell me? Thank you.作者: shiyiming 时间: 2003-10-23 21:48
Can you upload part of the xls file? Maybe you shuld set proper attribute in excel first.作者: shiyiming 时间: 2003-10-24 10:32
在SAS8.2中没有出现这样的问题,如果你用的是以前的版本,可以在LOG里面COPY出IMPORT所用的CODE,然后修改相关的INFORMAT, 设定你希望的长度,最后RUN相关的CODE即可解决问题.作者: shiyiming 时间: 2003-10-24 18:55
[quote="hannaqiu":01fa0]在SAS8.2中没有出现这样的问题,如果你用的是以前的版本,可以在LOG里面COPY出IMPORT所用的CODE,然后修改相关的INFORMAT, 设定你希望的长度,最后RUN相关的CODE即可解决问题.[/quote:01fa0]
不知可否?作者: shiyiming 时间: 2003-10-24 19:47
[color=red:8e20a]/*假定从XLS过来的数据,长度为255,EXCEL单元格文本的最大长度*/[/color:8e20a]
data _xls2sas;
length a b c $ 255;
input a b c;
datalines;
ss aaaaaaaa ssssssss
sssssssss aaa ssss
;
run;
[color=red:8e20a]/*获取informats, 但不正确,因为长度不对*/[/color:8e20a]
data _1(keep=CharVarName--______infmt);
set _xls2sas end =eof;
array CharVar(*) _character_ ;
do i = 1 to dim(CharVar);
CharVarName =vname(CharVar(i));
CharVarLeng =length(CharVar(i));
______infmt =trim(left(CharVarName))||' $'||trim(left(CharVarLeng))||'.';
output;
end;
run;
proc sort data=_1 out =_2;
by CharVarName DESCENDING CharVarLeng;
run;
/*只保留vlength最长的*/
proc sort data=_2 out =_2(keep=______infmt) nodupkey;
by CharVarName;
run;
[color=red:8e20a]
/*将各变量的变量名和最大长度并在一起,产生宏变量infmt*/[/color:8e20a]
proc sql noprint;
select ______infmt into : infmt separated by ' ' from _2;
quit;
*%put &infmt;
[color=red:8e20a]
/*仿照V8+的思路,重新设置informat和format*/[/color:8e20a]
data xls2sas;
informat &infmt.;
format &infmt.;
set _xls2sas;
run;
[color=red:8e20a]
/*清理多余的dataset和宏变量*/[/color:8e20a]
proc delete data=_1;run;
proc delete data=_2;run;
proc delete data=_xls2sas;run;
%symdel infmt;作者: shiyiming 时间: 2003-10-26 12:39
Thank you so much every one.
I asked that question. just want to make sure that it is a version problem or there has a system option. because I used version 6. to import execl2000 data file to sas and every thing is OK. while I used version 8.1
to do same thing and got that kind of problem. I don't know why ?
any way thanks again