Hi Tom,
Good that you checked the problem formulation - forces me to improve the structuring of the problem!
It is not a simple "travelling salesman" problem, the fastest route between two points, but rather the closest match, to a target stop, along a PT route. Thus, the first table of Message #9, which consists of only one card transaction, contains, in column #8, possible (candidate) stops based on network _walk_ distances to stops surrounding to stop in the 7th column (#7400003), which is the boarding stop of the _subsequent_ (next in time) PT trip (i e subsequent card transaction in the ticketing data). Note that all the rows in ths sample of the first table have the same values of column1-6 and thus belong to the same card transaction, with the boarding of the subsequent trip appended to it. (The boarding stop of the transaction itself is thus 7401547 - column #3).
What about the second table then? Well, it contains the trip itinerary of line route 817, in this case identified by the line route ID of the first column in table #1, and looked up in the trip itinerary database based on column #2 (table #2 of message #9). Now, the script should loop through the stops of column #8 of table #1 and compare them to the stops of column #4 in Table #2 and indicate the stop (in column #8 in Table #1) with the smallest value of either column #9 OR column #10 in Table #1. This should result in a '1' in column #10 of Table #3, which is just a reformulation of Table #1, plus the "flag" column.
As to what is missing in the code of the datasteps i provided in message #9, I am still lost in oblivion...
As to what is missing in the code of the datasteps i provided in message #9, I am still lost in oblivion...
For datastep data data.PossibleTargetStops7400003;
1.datalines1; is invalid syntax. It's either datalines or datalines4
2. column trs_dt is always missing due to missing informat.
3. you mention in the narrative card id no 10643 but I can't find such a column or value in the data you've posted.
4. is column Time of any relevance? And if yes what does a value of 20772.699931 mean? Are these seconds?
Thanks, @Patrick, for some concrete comments, finally! Il be back shortly with corrections, in message #9! /Ulrik
Sorry to be such a pain.
I know from own experience how hard it can be to ask a question if the problem is not trivial. I've also made the experience that it really helped me to get to the solution by being forced to reduce the problem to its core.
Try to provide as little data (rows and columns) as you can - but these as representative as possible.
Also try in your narrative to be as short and precise as you can be. And provide examples illustrating what you describe (as you've done already).
No worries, @Patrick 🙂
Just to be able to move on, I have issues importing the "time" column, as you may have noticed. I now changed it to 'hh:mm:ss' in the 24 hour-a-day version. What informat should I define for SAS to import it from datalines?
@ulricius wrote:
No worries, @Patrick 🙂
Just to be able to move on, I have issues importing the "time" column, as you may have noticed. I now changed it to 'hh:mm:ss' in the 24 hour-a-day version. What informat should I define for SAS to import it from datalines?
O.K., here your datastep for the first table "fixed". Please run it and check if the output looks like what you'd expect.
data work.PossibleTargetStops7400003;
infile datalines dsd truncover dlm=' ';
input
linje:$3. dep_num stp trs_dt :date9.
crd_num Time stp_t To Total_Mete Total_Seco;
format trs_dt date9.;
format time time.;
datalines;
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415574 412.0518591 296.6773356
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415600 471.70787795 339.62966984
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415847 564.73844061 406.61167038
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415576 620.70628168 446.90851942
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415723 632.69061063 455.53724234
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415571 749.44706581 539.6018891
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415724 893.89056819 643.60119944
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415745 928.47124344 668.4992945
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415577 1011.1364702 728.01825104
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415689 1020.296277 734.61330423
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415606 1137.1403793 818.74107625
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415816 1257.7971129 905.61392546
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415728 1269.5402379 914.06896269
817 2 7401547 14NOV2016 59 20772.699931 7400003 7413039 1330.3410244 957.84552638
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415732 1392.4036034 1002.5305784
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415624 1414.5585351 1018.4821456
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415690 1437.3201032 1034.8704716
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415580 1442.9038977 1038.8907905
817 2 7401547 14NOV2016 59 20772.699931 7400003 7415747 1470.6074832 1058.8373881
;
proc print data=work.PossibleTargetStops7400003;
run;
Since I don't seem to get any help in this thread, I have created a new one here:
@ulricius wrote:
Since I don't seem to get any help in this thread, I have created a new one here:
I think you received LOTS of help on this thread - asking for and making suggestions about problem clarification - probably the single most important skill one can learn with the help of forum members. I have seen the other thread, which is clear to me. But I didn't see its relationship to this one. Good luck.
Finally, a sufficient (partial) solution is now provided here https://communities.sas.com/t5/SAS-Programming/Creating-a-to-from-list-from-a-vector/m-p/630694/high..., courtesy of @FreelanceReinh .
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.