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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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