data long_data;
input team $ variable $ value;
datalines;
A Points 88
A Assists 12
A Rebounds 22
B Points 91
B Assists 17
B Rebounds 28
C Points 99
C Assists 24
C Rebounds 30
D Points 94
D Assists 28
D Rebounds 31
;
run;
proc transpose data=long_data out=wide_data name=variables;
by team;
id variable;
var value;
run;
One way is to use the data step.
proc sort data=long_data out=sorted;
by team;
run;
data wide_data2;
set sorted;
by team;
retain points assists rebounds;
if first.team then do;
Points=.;
Assists=.;
Rebounds=.;
end;
if variable='Points' then Points=value;
if variable='Assists' then Assists=value;
if variable='Rebounds' then Rebounds=value;
if last.team;
keep team points assists rebounds;
run;
@BrahmanandaRao wrote:
Using array method is it possible
What variable would you use as the index into the array?
data long_data;
input team $ variable $ value;
datalines;
A Points 88
A Assists 12
A Rebounds 22
B Points 91
B Assists 17
B Rebounds 28
C Points 99
C Assists 24
C Rebounds 30
D Points 94
D Assists 28
D Rebounds 31
;
run;
proc sql noprint;
select distinct catt('long_data(where=(variable="',variable,'") rename=(value=',variable,'))')
into :merge separated by ' '
from long_data;
quit;
data want;
merge &merge.;
by team;
drop variable;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.