Hello. I have data like this (see below), but it has over 4,000 patientID, encounterID, and date/time combinations. I want to be able to write code to condense the data down to 1 row per patientID, encounterID, date/time combination.
patientID | encounterID | Date/time | variable1 | variable2 | variable3 | variable4 | variable5 |
1 | 333 | 7/11/2016 19:01 | 6 | ||||
1 | 333 | 7/12/2016 19:01 | |||||
1 | 333 | 7/13/2016 19:01 | 13 | ||||
1 | 333 | 7/14/2016 19:01 | 15 | ||||
1 | 333 | 7/15/2016 19:01 | |||||
1 | 333 | 7/16/2016 19:01 | |||||
1 | 333 | 7/17/2016 19:01 | 8 | ||||
1 | 333 | 7/18/2016 19:01 | 24 | ||||
1 | 333 | 7/19/2016 19:01 | |||||
1 | 333 | 7/20/2016 19:01 |
So in the example above I would end up with 1 row like this (see below), but I want to use simple code to handle all of the 4,000+ combinations of patientID, encounterID, and date/time.
patientID | encounterID | Date/time | variable1 | variable2 | variable3 | variable4 | variable5 |
1 | 333 | 7/11/2016 19:01 | 13 | 24 | 15 | 6 |
8 |
Thanks!
proc summary data=have nway;
class patientid encounterid date_time;
var variable1-variable5;
output out=want sum=;
run;
proc summary data=have nway;
class patientid encounterid date_time;
var variable1-variable5;
output out=want sum=;
run;
That worked, thanks!
This assumes your data is sorted by the BY statement I have in there.
proc means
data = have noprint;
by patientid encounterid datetime;
var variable:;
output out = want (drop = _:)
max() = ;
run;
Produces something like this (note: I only reproduced part of your code since it wasn't in the DATALINES format.):
patientid encounterid variable1 variable2 variable3 variable4 variable5 1 333 13 24 15 6 8
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.