DATA Step, Macro, Functions and more

All observations in the last row sorted by person

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

All observations in the last row sorted by person

I have this:

 

Id    s1    s2    s3    s4    s5    s6    s7    s8    s9    s10    s11    s12

1     0      0      1      0      0     0      0      0      0        0       0        0

1     0      0      0      0      1     0      0      0      0        0       0        0

1     0      0      0      0      0     2      0      0      0        6       0        0

1     1      0      0      0      0     0      0      0      0        0       0        0

2     0      1      0      0      0     0      0      0      0        0       0        0

3     0      0      0      0      0     0      0      0      3        0       0        0  

3     0      1      0      0      0     0      0      0      0        0       0        0

4     0      0      0      0      0     0      0      0      0        0       0        0

5     0      0      1      0      0     0      0      0      0        0       0        0

5     0      0      0      1      0     0      0      3      0        0       6        0

 

How do I get this (all observations sorted by id in one row)?

 

Id    s1    s2    s3    s4    s5    s6    s7    s8    s9    s10    s11    s12

1     1      0      1      0      1     2      0      0      0        6       0        0

2     0      1      0      0      0     0      0      0      0        0       0        0

3     0      1      0      0      0     0      0      0      3        0       0        0  

4     0      0      0      0      0     0      0      0      0        0       0        0

5     0      0      1      1      0     0      0      3      0        0       6        0

 

 

 


Accepted Solutions
Solution
‎04-29-2016 03:10 AM
Super User
Posts: 9,691

Re: All observations in the last row sorted by person

CODE NOT TEST.

proc summary data=have;
by id;
var s: ;
output out=want max=;
run;

View solution in original post


All Replies
Super User
Posts: 5,260

Re: All observations in the last row sorted by person

Assuming that you have only one value <> 0 per variable and id use SQL with max () ... group by id.
Data never sleeps
Solution
‎04-29-2016 03:10 AM
Super User
Posts: 9,691

Re: All observations in the last row sorted by person

CODE NOT TEST.

proc summary data=have;
by id;
var s: ;
output out=want max=;
run;
Occasional Contributor
Posts: 15

Re: All observations in the last row sorted by person

Thanks a lot Xia Keshan!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 198 views
  • 0 likes
  • 3 in conversation