data temp; input id zip cntr $; cards; 1234 30004 USD 1234 30012 USD 1289 30056 USD 1389 45009 INR 1456 56789 INR 1456 30067 USD 1567 30099 USD 1567 67890 GBP 1567 30088 INR 1567 30092 INR ; proc sort data=temp(drop=zip) out=temp1 nodupkey; by id cntr; run; data temp2(drop=cntr); set temp1; retain cntry; length cntry $20.; by id cntr; if first.id and last.id then do; cntry=cntr; output temp2; end; else if first.id and last.id = 0 then do; cntry=cntr; end; else if first.id = 0 and last.id = 0 then do; cntry = catx(',',cntry,cntr); end; else if first.id = 0 and last.id = 1 then do; cntry = catx(',',cntry,cntr); output temp2; end; run;
... View more