BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

We have flight data that looks like:

 

SPECIALTY     FLT_BIZ_UID    FIR_NAME     DISTANCE
1             1234567        MONCTON      25
2             1234567        MONCTON      40
3             1234567        MONCTON      60
4             1234567        TORONTO      25
5             1234567        TORONTO      40
6             1234567        TORONTO      80
8             1234567        VANCOUVER    25
7             1234567        VANCOUVER    40
6             1234567        VANCOUVER    80

 

I would like to be able to select the first entry for each flight (flt_biz_uid) as it enters a different FIR (flight information region).

 

So the output would be:

 

FLT_BIZ_UID    FIR_NAME    
1234567        MONCTON     
1234567        TORONTO     
1234567        VANCOUVER

 

All this is doing is getting a track of a flight as it moves into different FIR regions (there can be many flights...many flt_biz_uid).  I had tried using .first, but could not get the syntax to work.

 

As a part two, is it possible to do the same thing but add a total distance column for each FIR?  For example:

 

FLT_BIZ_UID    FIR_NAME   DISTANCE 
1234567        MONCTON    125
1234567        TORONTO    145
1234567        VANCOUVER  145

 

thanks in advance

7 REPLIES 7
Reeza
Super User
Have you tried BY groups with the FIRST. logic?

https://onlinecourses.science.psu.edu/stat481/node/9/
novinosrin
Tourmaline | Level 20

part1

 

by FLT_BIZ_UID    FIR_NAME;

if first.FIR_NAME;

 

 

 

part 2:

proc means/summary/sql/datastep by group sum 

Reeza
Super User
Part 2 would generate part 1 in your sample data, but I expect that won't scale.
Astounding
PROC Star

It's probably just a coincidence that the FIR_NAMEs are in alphabetical order here.  They won't have to be if you use:

 

proc summary data=have;

by flt_biz_uid fir_name notsorted;

var distance;

out=want (drop=_: ) sum=;

run;

BCNAV
Quartz | Level 8

The following seems to work....should be ok?

 

data EGTASK.FDE_FIR_CLEAN; set EGTASK.FDE_FIR_CLEAN_TMP;

by FLT_BIZ_UID FIR_NAME;

if first.FIR_NAME then output;

run;

Astounding
PROC Star

That works or part 1 of your question, as long as the data set is in order that matches your BY statement.  

error_prone
Barite | Level 11
Seems to be ok. Don't use all updase names, they decrease readability.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1949 views
  • 2 likes
  • 5 in conversation