Here's a SQL solution, that first counts the number of devices per UserID and then assigns a 1 or 0 accordingly. proc sql; create table want as select a.*, case when b.num_devices=1 then 0 when b.num_devices>1 then 1 else . end as indicator from have as a join (select userID, count(distinct deviceid) as num_devices from have group by userID) as b on a.userid=b.userID; quit;
... View more