BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hein68
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
     class patientid encounterid date_time;
     var variable1-variable5;
     output out=want sum=;
run;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
     class patientid encounterid date_time;
     var variable1-variable5;
     output out=want sum=;
run;
--
Paige Miller
maguiremq
SAS Super FREQ

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 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 560 views
  • 1 like
  • 3 in conversation