Hi, I've got a dataset where each row is a unique identifer (ID), and 80 numerical variables containing percentages (a1 -- a80). I want to be able to loop through each column, set the highest X of rows (numerically) as 1 and the rest as 0. The issue is that X is different for each column, i.e for a1, x = 21%, a2, x = 50% ... a80, x = 14% etc I was thinking of using temporary arrays to store the value for the Xs but not sure how to entirely approach this. Thanks. Input dataset id a1 a2 a3 1 0.1 0.95 0.54 2 0.15 0.86 0.55 3 0.02 0.91 0.50 4 0.13 0.87 0.49 5 0.12 0.88 0.48 Expected output (e.g turn the largest 3,2,4 (I used integers instead of percentage here but either is fine) rows for a1, a2, a3 respectively into "1" and "0" else) id a1 a2 a3 1 0 1 1 2 1 0 1 3 0 1 1 4 1 0 1 5 1 0 0 This is what I thought of but doing it for 80 different variables would be quite tedious. proc sql inobs = 3; create table t_a1 as select id, a1 from input order by a1 DESC; quit; proc sql inobs = 2; create table t_a2 as select id, a2 from input order by a2 DESC; quit; proc sql inobs = 4; create table t_a3 as select id, a3 from input order by a3 DESC; quit; proc sql; create table merged as select * from t_a1 as a left join t_a2 as b on a.id = b.id; left join t_a3 as c on a.id = c.id; quit;
... View more