|
|
沙发

楼主 |
发表于 2009-8-4 20:52:02
|
只看该作者
Re: 关于数据集的转换
没太看明白,是这意思不? 效率不太高,凑合看吧.
[code:24v3c1vt]data aaa;
input a b v_c $ d e v_f $;
cards;
1 . . . . .
. 2.22222 . . . .
. . C . . .
. . . 4.44444 . .
. . . . 5 .
. . . . . F
;
%macro convert(inds,outds);
proc contents data=&inds out=_temp(keep=name type varnum) short noprint;
run;
proc sort data=_temp;
by varnum;
run;
data _temp;
set _temp end=last;
retain var_list var_type;
length var_list var_type $32767;
var_list=catx(',',var_list,name);
var_type=catx(',',var_type,put(type,8.));
if last then do;
call symput('var_list',strip(var_list));
call symput('type_list',strip(var_type));
call symput('var_num',strip(put(_n_,8.)));
end;
run;
proc datasets library=work nolist;
delete _temp;
run;
data &outds;
set &inds end=last;
array arr{&var_num} $ _temporary_;
%do i=1 %to &var_num;
%if %scan(%quote(&type_list),&i)=1 %then %do;
if _n_=&i then arr(&i)=put(%scan(%quote(&var_list),&i),8.);
%end;
%else %do;
if _n_=&i then arr(&i)=%scan(%quote(&var_list),&i);
%end;
%end;
if last then do;
%do i=1 %to &var_num;
%if %scan(%quote(&type_list),&i)=1 %then %do;
%scan(%quote(&var_list),&i)=input(arr(&i),8.);
%end;
%else %do;
%scan(%quote(&var_list),&i)=arr(&i);
%end;
%end;
output;
end;
run;
%mend;
%convert(work.aaa,work.bbb)[/code:24v3c1vt] |
|