SAS中文论坛

标题: 不同数据集之间的数据处理问题(数据标准化问题) [打印本页]

作者: shiyiming    时间: 2006-2-28 17:02
标题: 不同数据集之间的数据处理问题(数据标准化问题)
各位同仁,现急求救解答如下问题:如何将变量x的值减该变量的最小值,然后再除以最大值减最小值的差,即 x=(X-xmin)/(Xmax-Xmin)。

我的程序如下,但有问题,请帮助解决,先谢谢了。
data x(drop=id);
   input id $ a b c;
    cards;
          1  1 2 3
          2  3 4 5
          3  7 8 6
    ;
    run;


   proc means data=x ;output out=x1;run;

  data x2;set x1;if _STAT_='MIN' or _STAT_='MAX';
drop _FREQ_ _STAT_ _TYPE_ id;  run;

data x3;
    array x[3]  a b c;
    array x2[3,2] ;
        if _n_=1 then set x2; run;
            set x;
              do i=1 to 3;
        
          x[i]=(x[i]-x2[1,i])/(x2[2,i]-x2[1,i]);
              end;
    run;
作者: shiyiming    时间: 2006-3-1 09:58
标题: 一种实现方法
有朋友推荐了一种方法,各位看如何?是否需要改进!

data x;
   input id $ a b c;
    cards;
          1  1 2 6
          2  3 5 5
          3  7 8 3
    ;
    run;

*---find all var names and number of vars---*;

proc contents data=x noprint out=kk;
run;

*---get number of var and var names ------*;
*---and put them into macro variables-----*;

data _null_;
   set kk(where=(type=1)) end=lastone;
      call symput('varn_'||compress(_n_),compress(name));
         if lastone then do;
            call symput('numvar',compress(_n_));
            end;
run;
  %put _Global_;

   *---get max and min of all vars---------*;
proc means data=x noprint nway;
output out=sss(drop=_type_ _freq_) max= min= /
autoname;
run;

data x_m;
if _n_=1 then set sss;
set x;
run;

*---using macros to work var by var----*;
%macro xstand;
data x_result;
set x_m;
%do I =1% to &numvar.;
     new_&&varn_&I. = (&&varn_&I. - &&varn_&I.._min)/(&&varn_&I.._max-&&varn_&I.._min);
  %end;
  keep %do I =1 %to &numvar.;
           new_&&varn_&I.
        %end;   ;
run;
%mend;

%xstand;
作者: shiyiming    时间: 2006-3-1 18:10
标题: dsfsdfssssssssssss
[code:47afd]data x(drop=id);
  input id $ a b c;
  cards;
1 1 2 3
2 3 4 5
3 7 8 6
;
run;

%macro func(v);
  (&v-min(&v))/(max(&v)-min(&v)) as &v
%mend;

proc sql;
  create table final as
  select %func(a), %func(b), %func(c)
  from x;
quit;[/code:47afd]
作者: shiyiming    时间: 2006-3-3 17:10
标题: 谢谢!如果有50个变量该如何处理?
高手!谢谢! 如果有50个变量该如何处理?




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2