@Ronein,
Well, first, I agree with @andreas_lds and @PaigeMiller that transforming from long to wide is generally a poor idea. However, maybe it's for reporting or for export as a .csv file, so maybe it's worthwhile.
That said, here's one solution, below. The Call Missing() is probably unnecessary but is there at least in part to make it clear that the IPs are reset whenever there is a new ID. Below the code are the results.
%let CustomerIP=1234567;
Data have;
input ID CustomerIP;
cards;
111 1234567
222 1234567
333 8788888
444 8798777
555 8765432
222 8765432
222 7654221
111 8273774
;
Run;
PROC SORT DATA=Have;
BY ID CustomerIP;
RUN;
DATA Want;
DROP CustomerIP;
SET Have;
BY ID CustomerIP;
LENGTH IPs $32767;
RETAIN IPs;
IF FIRST.ID THEN
DO;
CALL MISSING(IPs);
IPs = STRIP(PUT(CustomerIP,8.));
END;
ELSE
DO;
IPs = CATS(IPs,',',PUT(CustomerIP,8.));
END;
IF LAST.ID;
IF INDEX(IPs , "&CustomerIP");
RUN;
Results:
Jim
... View more