전산Tip/SAS

[SAS] hash를 이용한 row 병합

모던아트 2011. 2. 21. 16:08
반응형


data    goals;
        input player $ when & $9.;
datalines;
Hill 1st 01:24
Jones 1st 09:43
Santos 1st 12:45
Santos 2nd 00:42
Santos 2nd 03:46
Jones 2nd 11:15
;

data    _null_;
        length goals_list $ 64;

        if _N_ = 1 then do;
                declare hash h();
                h.defineKey('player');
                h.defineData('player', 'goals_list');
                h.defineDone();
        end;

        set goals end=done;
        if h.find() ^= 0 then do;
                goals_list = when;
                h.add();
        end;
        else do;
                goals_list = trim(goals_list) || ', ' || when;
                h.replace();
        end;

        if done then
                h.output(dataset:'goal_summary');
run;