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
part1
by FLT_BIZ_UID FIR_NAME;
if first.FIR_NAME;
part 2:
proc means/summary/sql/datastep by group sum
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;
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;
That works or part 1 of your question, as long as the data set is in order that matches your BY statement.
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!
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.