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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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