The question is about calculating the minimum fee. I have a dataset called busfares, which contains different station code, the destation code, type of fares. So much thanks to all of you if you wish to spend some time on my question.
The dataset looks like this.
srt_na srt srt_id dest_na dest dest_id adult_pri student_pri child_pri eldery_pri
abcde abc 1 abcde abc 1 0 0 0 0
abcde abc 1 bbcde bbc 2 5 4 4 1
abcde abc 1 cbcde cbc 3 7 5 5 1
abcde abc 1 dbcde dbc 4 7 5 5 1
abcde abc 1 ebcde ebc 5 10 6 6 1
.
.
.
abcde abc 1 ooooo ooo 91 30.5 20 20 1
bbcde bbc 2 abcde abc 1 5 4 4 1
bbcde bbc 2 bbcde bbc 2 0 0 0 0
.
.
.
ooooo ooo 91 abcde abc 1 30.5 20 20 1
ooooo ooo 91 bbcde bbc 2 30.5 20 20 1
.
.
.
ooooo ooo 91 ooooo ooo 91 0 0 0
The question is how can I use four array to bulid the look up tables for different type of fares? The table should be look like that. And the row and column are representing different station name like row1 is representing abc, column1 is also representing abc as well
adult 1 2 3 4 ...
1 0 5 7 7 ...
2 5 0 10 10 ...
3 7 10 0 5 ...
4 7 10 5 0 ...
Now that I have my hands on a real keyboard instead of a handheld, here's a way to set up 4 two-dimensional arrays:
data want;
if _n_=1 then do;
array adult {91, 91} _temporary_;
array student {91, 91} _temporary_;
array child {91, 91} _temporary_;
array elderly {91, 91} _temporary_;
do until (done);
set have end=done;
adult{srt_id, dest_id} = min(adult_pri, adult{srt_id, dest_id} ) ;
student{srt_id, dest_id} = min(student_pri, student{srt_id, dest_id} ) ;
child{srt_id, dest_id} = min(child_pri, child{srt_id, dest_id} ) ;
elderly{srt_id, dest_id} = min(elderly_pri, elderly{srt_id, dest_id} ) ;
end;
end;
* more DATA step code here to utilize the arrays;
The original question mentions something about finding the minimum price, which is the reason for applying the MIN function. It's possible that I'm overcomplicating the problem in that regard.
Do not use the array names (student, adult, child, elderly) as variable names in the same DATA step.
There is a DO loop that says:
do until (done);
That loop accomplishes both of the things you are asking about.
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.