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

I have airline origin and destination data that looks like:

 

Departure   Destination    Current Count    Previous Count

CYEG        CYYZ           51               22

CYYZ        CYEG           53               67

RPLL        CYYZ           21                6

CYVR        CYYC           11                9

CYYC        CYVR           15                1

 

 

What really matters is the total traffic between COMMON city pairs. What would be good would be to get output as:

 

Common City Pair   Current Count   Previous Count

CYEG <--> CYYZ     104             89

RPLL <--> CYYZ      21              6

CYVR <--> CYYC      26             10

 

 

The values in the Current Count and Previous count are now the sums of the COMMON city pairs in the original data. Common city pairs can be anywhere in the dataset and not necessarily right after one another.

 

Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Create two new variables and use CALL SORTC() on them to sort the two variables and then summarize on those.


data temp;
set have;
loc1 = origin;
loc2 = destination;
call sortc(loc1, loc2);
run;

proc means data=temp NWAY;
class loc1 loc2;
var current_count prev_count;
output out=want sum= /autoname;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User
Create two new variables and use CALL SORTC() on them to sort the two variables and then summarize on those.


data temp;
set have;
loc1 = origin;
loc2 = destination;
call sortc(loc1, loc2);
run;

proc means data=temp NWAY;
class loc1 loc2;
var current_count prev_count;
output out=want sum= /autoname;
run;
BCNAV
Quartz | Level 8

thanks!!

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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