BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
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;
1 ACCEPTED SOLUTION

Accepted Solutions
japelin
Rhodochrosite | Level 12
What do you want to do?
Please describe your question properly.

View solution in original post

7 REPLIES 7
japelin
Rhodochrosite | Level 12
What do you want to do?
Please describe your question properly.
BrahmanandaRao
Lapis Lazuli | Level 10
any alternative methods instead of proc transpose
japelin
Rhodochrosite | Level 12

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
Lapis Lazuli | Level 10
Using array method is it possible
PaigeMiller
Diamond | Level 26

@BrahmanandaRao wrote:
Using array method is it possible

No array for your data

--
Paige Miller
Tom
Super User Tom
Super User

@BrahmanandaRao wrote:
Using array method is it possible

What variable would you use as the index into the array?

 

Ksharp
Super User
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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 976 views
  • 1 like
  • 5 in conversation