Hi,
I'm a SAS newbie, and I have a pretty simple question:
I have about 20 data sets representing specific sections of a road network, and each have 2 columns that I am interested in: Vehicle_ID and Time_Step. At each time step (1 second), the data set lists the the vehicles which are at a particular position on that section of the road. I would like to match the Vehicle_ID in all tables and obtain the vehicles that are travelling along the entire route in the
network. For each of these vehicles, I would like to find the total travel from from the time steps. I was wondering if there is a simple way in which to filter the data in each data set to give me the
Vehicle_IDs and a count of the corresponding Time_Steps in which the vehicle appeared on the section. For example, if Vehicle 2242 was found to be in the data set at Time_Steps 43, 44, 45, 46, 47, 48 then it was travelling for 6 seconds on that section. Its a relatively simple calculation but I am having trouble performing the filtering on 20+ large data sets.
I would really appreciate it anyone could give me some advice on how I might be able to do this in SAS or forward my question to someone who could help me.
Thanks in advance!
Anya
Then wouldn't something like the following suffice?:
data have;
input vehicle time_step;
cards;
1 23
1 24
1 25
2 52
2 53
2 54
2 55
3 34
3 35
;
proc sql;
create table want as
select distinct vehicle,
max(time_step)-min(time_step) +1
as seconds
from have
group by vehicle
;
quit;
A couple of questions:
Does it have to be a filtering specific solution or can it be a datastep or proc sql solution
Is there a chance that vehciles might have missing Time_Steps and, if so, what would you want as a result if a vehicle had something like Time_Steps 43, 44, 46, 47, 48? or 1,2,3,46,47,48?
Hello!
1. It doesn't have to be a filtering specific solution.
2. I think the time steps would generally be in a sequence because a simulation tracked the vehicle's position through a particular section for every second - so its not likely that the time steps will look like 1,2,3,46,47,48 because (hopefully) no vehicles get sucked into a black hole of traffic while travelling on a section
Then wouldn't something like the following suffice?:
data have;
input vehicle time_step;
cards;
1 23
1 24
1 25
2 52
2 53
2 54
2 55
3 34
3 35
;
proc sql;
create table want as
select distinct vehicle,
max(time_step)-min(time_step) +1
as seconds
from have
group by vehicle
;
quit;
Thank you..it worked!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.