I have a categorical column in my dataset which has around 20 or more categories. Now I want to create seperate dataset for all these categories.
Example: if the category is A, B, C, …. then I need table A containing A data, table B containing B data etc.
>Solution :
A classic use of the SAS Hash Object
data have;
input category $ value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
C 9
;
data want;
if _N_ = 1 then do;
dcl hash h(dataset : 'have(obs = 0)', multidata : 'Y');
h.definekey(all : 'Y');
h.definedone();
end;
do until (last.category);
set have;
by category;
h.add();
end;
h.output(dataset : catx('_', 'table', category));
h.clear();
run;