DATA Step, Macro, Functions and more

Consolidate columns into 1 cell for each person

Reply
Contributor
Posts: 37

Consolidate columns into 1 cell for each person

I have a dataset with a list of different tox results for each person. One person could have as many as 200 tests, so using transpose by ID is not useful. We need to search for text for particular tests, so it will be better to put all the tests (each test now is in rows all with the same ID) into once cell and only have one row with one cell of test results for each patient.

 

Any help will be appreciated!

 

Super User
Posts: 17,831

Re: Consolidate columns into 1 cell for each person

 

So is your data long and you want to make it wide, or is it wide and you want to make it long. 


In my experience the long format is easier to filter out, since you can use a WHERE or IF clause, compared to looping through an array. 

Valued Guide
Posts: 2,175

Re: Consolidate columns into 1 cell for each person

Agreeing with @Reeza but you asked:
assuming data ordered by ID
data wide( compress= yes ) ;
Do until( last.id ) ;
Set your.data( keep= id tox ) ;
By id ;
Length toxM $1000 ; * up to 32767 wide would be valid ;
ToxM = catX( ' ', toxM, tox ) ;
End ;
Run;
Valued Guide
Posts: 2,175

Re: Consolidate columns into 1 cell for each person

probably should add
Drop tox ;
Ask a Question
Discussion stats
  • 3 replies
  • 234 views
  • 0 likes
  • 3 in conversation