BookmarkSubscribeRSS Feed
lerdem
Quartz | Level 8

Hi,

I have a table as below:

 

 term      classday            crn     room      begin_time       end_time

2016     17feb2015         201     110          0700               0750

2016     17feb2015         206     110          1000               1100

2016     17feb2015         150     110          1500               1550

2016     17feb2015         150     110          1700               1730

2016     18feb2015         250     120          1500               1550

2016     18feb2015         201     120          1600                1700

2016     18feb2015         203     120           1600                1650

2016     18feb2015         202     133           1500               1600 

 

These are class days, class room, class times.  I need to find for each room latest class. So i need tol pull

 

 term      classday            crn     room      begin_time       end_time

 

2016     17feb2015         150     110          1700               1730

2016     18feb2015         201     120          1600                1700

2016     18feb2015         202     133           1500               1600 

 

 

4 REPLIES 4
DanZ
Obsidian | Level 7
proc sort data=have;
by room end_time;
run;

data want;
set have;
by room end_time;
if last.room then output;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

proc sort, by room date time, then datastep, by room, if first.room then output.  

proc sort data=have;
  by room date time;
run;
data want;
  set have;
  by room;
  if first.room;
run;

Or SQL max date time.  There are many examples on here of this.

ad123123
Fluorite | Level 6

Hi,

 

You can use following SQL query:-

proc sql;
create table want as select * from have t1 
where end_time=(select max(end_time) from have t2 where t1.term=t2.term 
and t1.classday=t2.classday 
and t1.room=t2.room
group by term,classday,room);
quit;

Please let me know if it helps you.

 

Regards,

Abd.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 962 views
  • 0 likes
  • 5 in conversation