Tuesday, June 7, 2022

Hash way to split SAS Table

In traditional SAS way, it will leverage SAS macro to split the SAS dataset. If you are bored with that, you may like the hash way below. Enjoy!
proc sort data=sashelp.class out=class;
    by age;
run;

data _null_ ;
    declare hash h (multidata:"Y", 
    				ordered: "a", 
    				dataset:"class(obs=0)") ;
    h.definekey('name') ;
    h.definedata(all:'Y');
    h.definedone() ;

    do i = 1 by 1 until (last.age);
        set class;
        by age;
        h.add();
    end ;

    h.output(dataset: cats("age_", age));
run;

No comments: