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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.