BookmarkSubscribeRSS Feed
cesararevalo
Calcite | Level 5

I have data that looks like this with duplicate ID.

ID is unique to an individual, test is dichotomous and score is continuous 

id test score

1   2    3

1   1     2

1    2     9

2   1     5

3    2    3

4   1     3

4   1     8

 

I need It too look like this

id test score test2 score2  test3 score3

1   2     3        1     2             2        9

2   1     5

3    2    3

4   1     3        1     8

 

 

3 REPLIES 3
SK_11
Obsidian | Level 7

Hi cesararevalo

I hope this helps, here is the code which produces your output

data have;
input id test score;
datalines;
1 2 3
1 1 2
1 2 9
2 1 5
3 2 3
4 1 3
4 1 8
;
run;
proc transpose data=have out=want (drop=_NAME_) prefix=score;
By id;
var score ;
run;
proc transpose data=have out=want1 (drop=_NAME_) prefix=test;
By id;
var test ;
run;

data final;
retain id test1 score1 test2 score2 test3 score3 ;
merge want want1;
run;

 

The output is same as you wanted

idtest1score1test2score2test3score3
1231229
215....
323....
41318..

 

 

Ksharp
Super User
data have;
input id test score;
datalines;
1 2 3
1 1 2
1 2 9
2 1 5
3 2 3
4 1 3
4 1 8
;
proc sql noprint;
select max(n) into : n 
 from (select count(*) as n from have group by id);
quit;
proc summary data=have ;
by id;
output out=want idgroup(out[&n] (test score)=);
run;
ballardw
Super User

Just to continue my obnoxious streak of asking this question: What exactly to you expect to do with this wide structure that can't be done with the existing structure?

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 3 replies
  • 995 views
  • 0 likes
  • 4 in conversation