04.IT Knowledge/SAS

Datastep과 SQL 비교

아주 오래된 미래 2007. 4. 27. 16:48
상황에 따라 다르겠지만....

/* 실행시간 : 5.12sec */
proc sql;
create table target as
select distinct
       tname
     , cname
     , sum(cnt) as scnt
 from code_freq_master
 group by tname, cname;

create table code_freq_master1 as
select a.yyyymmdd
     , a.tname                                    label="테이블명"
     , a.cname
     , a.vname
     , a.cnt
     , (a.cnt/b.scnt)*100   as cratio format=6.2  label="분포비율"
  from target as b
 inner join code_freq_master a
         on a.tname = b.tname
        and a.cname = b.cname;
quit;
/* 실행시간 : 0.26 + 3.25 + 0.03 + 2.50 = 6.04 */
proc means data=code_freq_master noprint;
       var cnt;
     class tname cname;
    output out=tmp1(where=(_type_=3) ) sum=sum;
run;
proc sort data=code_freq_master ; by tname cname; run;
proc sort data=tmp1 ; by tname cname; run;
data code_freq_master2;
merge code_freq_master(in=in1) tmp1(in=in2 drop=_type_ _freq_);
   by tname cname;
      percent=cnt/sum*100;
   if in1 and in2;
label percent='분포비율'
      sum='합계';
run;


********************************************
*
* Do your best!!
*
* Homepage : http://www.javarang.net
* Javarang Lee
*
********************************************