Hello,
I am looking to transpose the below data as shown in the output. Any help is appreciated. Thanks!!
data rt;
input zip $5. empid 8.;
cards;
19701 8798
19701 5489
18054 3578
78945 3157
19701 7845
18045 2245
;
Run;
Output:
Zip | empid1 | empid2 | empid3 |
19701 | 8798 | 5489 | 7845 |
18054 | 3578 | 2245 | |
78945 | 3157 |
Set a counter for use in proc transpose:
data rt;
input zip $5. empid 8.;
cards;
19701 8798
19701 5489
18054 3578
78945 3157
19701 7845
18054 2245
;
run;
proc sort data=rt;
by zip;
run;
data rt1;
set rt;
by zip;
if first.zip
then count = 1;
else count + 1;
run;
proc transpose
data=rt1
out=want (drop=_name_)
prefix=empid
;
by zip;
id count;
var empid;
run;
Set a counter for use in proc transpose:
data rt;
input zip $5. empid 8.;
cards;
19701 8798
19701 5489
18054 3578
78945 3157
19701 7845
18054 2245
;
run;
proc sort data=rt;
by zip;
run;
data rt1;
set rt;
by zip;
if first.zip
then count = 1;
else count + 1;
run;
proc transpose
data=rt1
out=want (drop=_name_)
prefix=empid
;
by zip;
id count;
var empid;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.