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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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