Hello,
I have a dataset with thousands of observations, and need to reclassify hundreds of observations in three different variables, including the lookup/key variable. I'm trying to use a hash table but my current code simply adds the hash table variables to the old dataset and (mostly) codes them as missing. What am I doing wrong?
*Hash table;
data reclass;
input key new_key new_var1 new_var2;
datalines;
2 1 . 9
17 1 . 17
32 1 . 3
33 1 . 14
41 1 . 15
;
run;
*Applying hash table to dataset old;
data output;
length key new_key new_var1 new_var2 8.;
if 0 then set old reclass;
if _N_ = 1 then do;
Declare hash w (dataset:'reclass', ordered:'Y');
w.defineKey ("key");
w.defineData("key","new_key", "new_var1", "new_var2");
w.defineDone();
w.replace(key:17, data: 17, data:1, data:., data:7);
w.replace(key:2, data: 2, data:1, data:., data:9);
w.replace(key:32, data:32, data:1, data:., data:3);
w.replace(key:33, data:33, data:1, data:., data:14);
w.replace(key:41, data:41, data:1, data:., data:15);
w.output (dataset:'test');
w.delete ();
end;
set old;
run;