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

I have a dataset flight_demo which had 4 column namely origin, dest, carrier ,dep_time

I want to find the bussiest time in a day for each carrier from dep_time column

 

My code is:

PROC SQL;
CREATE TABLE  xyz AS
SELECT * FROM(SELECT DISTINCT DEP_TIME,CARRIER,n(DEP_TIME) AS N
FROM CASE_1.FLIGHTM
GROUP BY CARRIER,DEP_TIME
)
ORDER BY N DESC
;
QUIT;
RUN;

 

The problem with the output is that it gives for each time how many flight are departed from carrier

 

 

 

 

 

 

 

 

Capture.PNG

what I want is only the bussiest time by each carrier like for example

18:59    DL 167

 8:54     UA 166

 7:55     B6 160

  5:55    EV 158

 

i am not able to rectify how to do it using proc sql.

Is there any other method to do such stuff?

Any help will appreciate.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Finding the mode (maximum density) of a distribution from a sample is not a trivial problem. If you don't mind using the magic of statistical procedures, the following will do the job:

 

proc sort data=sasforum.Flight_demo out=fd; by carrier; run;
 
proc kde data=fd;
by carrier;
univar departuretime / out=fdDist plots=none;
run;

proc sql;
create table busyTime as
select carrier, value as busyTime format=time.
from fdDist
group by carrier
having density=max(density);
quit;

This method might miss departure peaks situated around midnight on rare occasions.

 

PG

View solution in original post

2 REPLIES 2
Reeza
Super User

You won't want to consider time as shown, you'd want to group it by hour or half hour. 

You should calculate that new variable first, within your query or not, and then test your results with a grouping by hour. 

 

PGStats
Opal | Level 21

Finding the mode (maximum density) of a distribution from a sample is not a trivial problem. If you don't mind using the magic of statistical procedures, the following will do the job:

 

proc sort data=sasforum.Flight_demo out=fd; by carrier; run;
 
proc kde data=fd;
by carrier;
univar departuretime / out=fdDist plots=none;
run;

proc sql;
create table busyTime as
select carrier, value as busyTime format=time.
from fdDist
group by carrier
having density=max(density);
quit;

This method might miss departure peaks situated around midnight on rare occasions.

 

PG

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
  • 2 replies
  • 834 views
  • 2 likes
  • 3 in conversation