338.TRANSPORTATION SYSTEMS PERFORMANCE ANALYSIS USING DATA STEP | PROC SQL | PROC MEANS | PROC SGPLOT | PROC CORR | MACROS | DATE FUNCTIONS (INTCK | INTNX)
TRANSPORTATION SYSTEMS PERFORMANCE ANALYSIS USING DATA STEP | PROC SQL | PROC MEANS | PROC SGPLOT | PROC CORR | MACROS | DATE FUNCTIONS (INTCK | INTNX)
options nocenter;
1.CREATE THE DATASET OF TRANSPORT_SYSTEMS
data transport_systems;
infile datalines dlm=',' truncover;
input Transport_Type :$20. Country :$20. Speed Capacity Energy_Consumption Cost
Safety_Index Start_Date :date9.;
format Start_Date date9.;
datalines;
Metro,India,80,1500,45,200,85,01JAN2010
Tram,Germany,60,300,25,150,90,01JAN2005
Hyperloop,USA,1000,50,120,5000,95,01JAN2025
Monorail,Japan,90,800,40,400,92,01JAN2012
Bullet_Train,France,320,900,60,1500,93,01JAN2008
Maglev,China,430,1000,70,2500,97,01JAN2016
Cable_Car,Switzerland,25,20,15,80,98,01JAN2000
Ferry,Norway,40,200,100,300,88,01JAN1995
Electric_Bus,UK,55,100,20,120,89,01JAN2018
Aerial_Tram,Austria,22,25,18,75,94,01JAN2003
Suspended_Monorail,Brazil,70,600,35,220,87,01JAN2014
High_Speed_Rail,Spain,300,1100,58,1400,96,01JAN2011
;
run;
proc print data=transport_systems;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date |
|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | 85 | 01JAN2010 |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | 90 | 01JAN2005 |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | 95 | 01JAN2025 |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | 92 | 01JAN2012 |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | 93 | 01JAN2008 |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | 97 | 01JAN2016 |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | 98 | 01JAN2000 |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | 88 | 01JAN1995 |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | 89 | 01JAN2018 |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | 94 | 01JAN2003 |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | 87 | 01JAN2014 |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | 96 | 01JAN2011 |
2.MACRO FOR RATING CLASSIFICATION
%macro classify(var=, out=);
if &var >= 95 then &out = "Excellent";
else if &var >= 90 then &out = "Very_Good";
else if &var >= 85 then &out = "Good";
else if &var >= 80 then &out = "Moderate";
else &out = "Poor";
%mend classify;
data transport_with_rating;
set transport_systems;
%classify(var=Safety_Index, out=Rating);
run;
proc print data=transport_with_rating;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date | Rating |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | 85 | 01JAN2010 | Good |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | 90 | 01JAN2005 | Very_Good |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | 95 | 01JAN2025 | Excellent |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | 92 | 01JAN2012 | Very_Good |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | 93 | 01JAN2008 | Very_Good |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | 97 | 01JAN2016 | Excellent |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | 98 | 01JAN2000 | Excellent |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | 88 | 01JAN1995 | Good |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | 89 | 01JAN2018 | Good |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | 94 | 01JAN2003 | Very_Good |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | 87 | 01JAN2014 | Good |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | 96 | 01JAN2011 | Excellent |
3.USE PROC SQL TO ADD DATE-BASED DERIVATIONS
proc sql;
create table transport_enhanced as
select *,
intck('year', Start_Date, today()) as Years_Operational,
intnx('year', Start_Date, 5) as Five_Year_Mark format=date9.
from transport_with_rating;
quit;
proc print data=transport_enhanced;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date | Rating | Years_Operational | Five_Year_Mark |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | 85 | 01JAN2010 | Good | 15 | 01JAN2015 |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | 90 | 01JAN2005 | Very_Good | 20 | 01JAN2010 |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | 95 | 01JAN2025 | Excellent | 0 | 01JAN2030 |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | 92 | 01JAN2012 | Very_Good | 13 | 01JAN2017 |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | 93 | 01JAN2008 | Very_Good | 17 | 01JAN2013 |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | 97 | 01JAN2016 | Excellent | 9 | 01JAN2021 |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | 98 | 01JAN2000 | Excellent | 25 | 01JAN2005 |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | 88 | 01JAN1995 | Good | 30 | 01JAN2000 |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | 89 | 01JAN2018 | Good | 7 | 01JAN2023 |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | 94 | 01JAN2003 | Very_Good | 22 | 01JAN2008 |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | 87 | 01JAN2014 | Good | 11 | 01JAN2019 |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | 96 | 01JAN2011 | Excellent | 14 | 01JAN2016 |
4.ADDITIONAL DATE METRICS (INTERVAL TREND ANALYTICS)
data transport_enhanced;
set transport_enhanced;
Days_Operational = intck('day', Start_Date, today());
Quarter_Mark = intnx('qtr', Start_Date, 1);
format Quarter_Mark date9.;
run;
proc print data=transport_enhanced;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date | Rating | Years_Operational | Five_Year_Mark | Days_Operational | Quarter_Mark |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | 85 | 01JAN2010 | Good | 15 | 01JAN2015 | 5826 | 01APR2010 |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | 90 | 01JAN2005 | Very_Good | 20 | 01JAN2010 | 7652 | 01APR2005 |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | 95 | 01JAN2025 | Excellent | 0 | 01JAN2030 | 347 | 01APR2025 |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | 92 | 01JAN2012 | Very_Good | 13 | 01JAN2017 | 5096 | 01APR2012 |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | 93 | 01JAN2008 | Very_Good | 17 | 01JAN2013 | 6557 | 01APR2008 |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | 97 | 01JAN2016 | Excellent | 9 | 01JAN2021 | 3635 | 01APR2016 |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | 98 | 01JAN2000 | Excellent | 25 | 01JAN2005 | 9479 | 01APR2000 |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | 88 | 01JAN1995 | Good | 30 | 01JAN2000 | 11305 | 01APR1995 |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | 89 | 01JAN2018 | Good | 7 | 01JAN2023 | 2904 | 01APR2018 |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | 94 | 01JAN2003 | Very_Good | 22 | 01JAN2008 | 8383 | 01APR2003 |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | 87 | 01JAN2014 | Good | 11 | 01JAN2019 | 4365 | 01APR2014 |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | 96 | 01JAN2011 | Excellent | 14 | 01JAN2016 | 5461 | 01APR2011 |
5.CREATING NEW VARIABLE
data logic_speed;
set transport_enhanced;
Speed_Growth = Years_Operational / Speed;
run;
run;
proc print data=logic_speed;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date | Rating | Years_Operational | Five_Year_Mark | Days_Operational | Quarter_Mark | Speed_Growth |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | 85 | 01JAN2010 | Good | 15 | 01JAN2015 | 5826 | 01APR2010 | 0.18750 |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | 90 | 01JAN2005 | Very_Good | 20 | 01JAN2010 | 7652 | 01APR2005 | 0.33333 |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | 95 | 01JAN2025 | Excellent | 0 | 01JAN2030 | 347 | 01APR2025 | 0.00000 |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | 92 | 01JAN2012 | Very_Good | 13 | 01JAN2017 | 5096 | 01APR2012 | 0.14444 |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | 93 | 01JAN2008 | Very_Good | 17 | 01JAN2013 | 6557 | 01APR2008 | 0.05313 |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | 97 | 01JAN2016 | Excellent | 9 | 01JAN2021 | 3635 | 01APR2016 | 0.02093 |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | 98 | 01JAN2000 | Excellent | 25 | 01JAN2005 | 9479 | 01APR2000 | 1.00000 |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | 88 | 01JAN1995 | Good | 30 | 01JAN2000 | 11305 | 01APR1995 | 0.75000 |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | 89 | 01JAN2018 | Good | 7 | 01JAN2023 | 2904 | 01APR2018 | 0.12727 |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | 94 | 01JAN2003 | Very_Good | 22 | 01JAN2008 | 8383 | 01APR2003 | 1.00000 |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | 87 | 01JAN2014 | Good | 11 | 01JAN2019 | 4365 | 01APR2014 | 0.15714 |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | 96 | 01JAN2011 | Excellent | 14 | 01JAN2016 | 5461 | 01APR2011 | 0.04667 |
/* Note: In practice above there is an Invalid in this code Find it,Correct it and Use it /*
6.PROC MEANS FOR SUMMARY STATISTICS
proc means data=transport_enhanced mean std min max maxdec=2;
var Speed Capacity Energy_Consumption Cost Safety_Index Years_Operational;
run;
OUTPUT:
The MEANS Procedure
| Variable | Mean | Std Dev | Minimum | Maximum |
|---|---|---|---|---|
Speed Capacity Energy_Consumption Cost Safety_Index Years_Operational | 207.67 549.58 50.50 995.42 92.00 15.25 | 284.21 503.54 33.15 1475.78 4.20 8.25 | 22.00 20.00 15.00 75.00 85.00 0.00 | 1000.00 1500.00 120.00 5000.00 98.00 30.00 |
7.CORRELATION ANALYSIS (PROC CORR)
proc corr data=transport_enhanced plots=matrix;
var Speed Capacity Energy_Consumption Cost Safety_Index;
run;
OUTPUT:
The CORR Procedure
| 5 Variables: | Speed Capacity Energy_Consumption Cost Safety_Index |
|---|
| Simple Statistics | ||||||
|---|---|---|---|---|---|---|
| Variable | N | Mean | Std Dev | Sum | Minimum | Maximum |
| Speed | 12 | 207.66667 | 284.21002 | 2492 | 22.00000 | 1000 |
| Capacity | 12 | 549.58333 | 503.53504 | 6595 | 20.00000 | 1500 |
| Energy_Consumption | 12 | 50.50000 | 33.14568 | 606.00000 | 15.00000 | 120.00000 |
| Cost | 12 | 995.41667 | 1476 | 11945 | 75.00000 | 5000 |
| Safety_Index | 12 | 92.00000 | 4.19957 | 1104 | 85.00000 | 98.00000 |
| Pearson Correlation Coefficients, N = 12 Prob > |r| under H0: Rho=0 | |||||
|---|---|---|---|---|---|
| Speed | Capacity | Energy_Consumption | Cost | Safety_Index | |
| Speed | 1.00000 | -0.00318 0.9922 | 0.75152 0.0048 | 0.99552 <.0001 | 0.41960 0.1745 |
| Capacity | -0.00318 0.9922 | 1.00000 | 0.06265 0.8466 | -0.00640 0.9843 | -0.19690 0.5396 |
| Energy_Consumption | 0.75152 0.0048 | 0.06265 0.8466 | 1.00000 | 0.77012 0.0034 | 0.08360 0.7962 |
| Cost | 0.99552 <.0001 | -0.00640 0.9843 | 0.77012 0.0034 | 1.00000 | 0.45281 0.1394 |
| Safety_Index | 0.41960 0.1745 | -0.19690 0.5396 | 0.08360 0.7962 | 0.45281 0.1394 | 1.00000 |
8.VISUALIZATION USING PROC SGPLOT
proc sgplot data=transport_enhanced;
scatter x=Speed y=Cost / group=Transport_Type;
title "Speed vs Cost Across Transportation Systems";
run;
OUTPUT:
proc sgplot data=transport_enhanced;
vbar Transport_Type / response=Safety_Index datalabel;
title "Safety Index by Transport Type";
run;
OUTPUT:
9.FORMATS FOR RATING GROUPING
proc format;
value safetyfmt
95 - high = 'Excellent'
90 -< 95 = 'Very Good'
85 -< 90 = 'Good'
80 -< 85 = 'Moderate'
low -< 80 = 'Poor';
run;
LOG:
proc print data=transport_enhanced;
format Safety_Index safetyfmt.;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date | Rating | Years_Operational | Five_Year_Mark | Days_Operational | Quarter_Mark |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | Good | 01JAN2010 | Good | 15 | 01JAN2015 | 5826 | 01APR2010 |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | Very Good | 01JAN2005 | Very_Good | 20 | 01JAN2010 | 7652 | 01APR2005 |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | Excellent | 01JAN2025 | Excellent | 0 | 01JAN2030 | 347 | 01APR2025 |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | Very Good | 01JAN2012 | Very_Good | 13 | 01JAN2017 | 5096 | 01APR2012 |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | Very Good | 01JAN2008 | Very_Good | 17 | 01JAN2013 | 6557 | 01APR2008 |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | Excellent | 01JAN2016 | Excellent | 9 | 01JAN2021 | 3635 | 01APR2016 |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | Excellent | 01JAN2000 | Excellent | 25 | 01JAN2005 | 9479 | 01APR2000 |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | Good | 01JAN1995 | Good | 30 | 01JAN2000 | 11305 | 01APR1995 |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | Good | 01JAN2018 | Good | 7 | 01JAN2023 | 2904 | 01APR2018 |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | Very Good | 01JAN2003 | Very_Good | 22 | 01JAN2008 | 8383 | 01APR2003 |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | Good | 01JAN2014 | Good | 11 | 01JAN2019 | 4365 | 01APR2014 |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | Excellent | 01JAN2011 | Excellent | 14 | 01JAN2016 | 5461 | 01APR2011 |
10.PROC SQL FOR COST PER CAPACITY ANALYSIS
proc sql;
create table cost_efficiency as
select Transport_Type, Country, Cost, Capacity,
(Cost / Capacity) as Cost_Per_Seat
from transport_enhanced;
quit;
proc print data=cost_efficiency;
run;
OUTPUT:
| Obs | Transport_Type | Country | Cost | Capacity | Cost_Per_Seat |
|---|---|---|---|---|---|
| 1 | Metro | India | 200 | 1500 | 0.133 |
| 2 | Tram | Germany | 150 | 300 | 0.500 |
| 3 | Hyperloop | USA | 5000 | 50 | 100.000 |
| 4 | Monorail | Japan | 400 | 800 | 0.500 |
| 5 | Bullet_Train | France | 1500 | 900 | 1.667 |
| 6 | Maglev | China | 2500 | 1000 | 2.500 |
| 7 | Cable_Car | Switzerland | 80 | 20 | 4.000 |
| 8 | Ferry | Norway | 300 | 200 | 1.500 |
| 9 | Electric_Bus | UK | 120 | 100 | 1.200 |
| 10 | Aerial_Tram | Austria | 75 | 25 | 3.000 |
| 11 | Suspended_Monorail | Brazil | 220 | 600 | 0.367 |
| 12 | High_Speed_Rail | Spain | 1400 | 1100 | 1.273 |
data transport_final;
set transport_enhanced;
Next_Upgrade = intnx('year', Start_Date, 15);
Cycles = intck('month', Start_Date, today());
format Next_Upgrade date9.;
run;
proc print data=transport_final;
run;
OUTPUT:
| Obs | Transport_Type | Country | Speed | Capacity | Energy_Consumption | Cost | Safety_Index | Start_Date | Rating | Years_Operational | Five_Year_Mark | Days_Operational | Quarter_Mark | Next_Upgrade | Cycles |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Metro | India | 80 | 1500 | 45 | 200 | 85 | 01JAN2010 | Good | 15 | 01JAN2015 | 5826 | 01APR2010 | 01JAN2025 | 191 |
| 2 | Tram | Germany | 60 | 300 | 25 | 150 | 90 | 01JAN2005 | Very_Good | 20 | 01JAN2010 | 7652 | 01APR2005 | 01JAN2020 | 251 |
| 3 | Hyperloop | USA | 1000 | 50 | 120 | 5000 | 95 | 01JAN2025 | Excellent | 0 | 01JAN2030 | 347 | 01APR2025 | 01JAN2040 | 11 |
| 4 | Monorail | Japan | 90 | 800 | 40 | 400 | 92 | 01JAN2012 | Very_Good | 13 | 01JAN2017 | 5096 | 01APR2012 | 01JAN2027 | 167 |
| 5 | Bullet_Train | France | 320 | 900 | 60 | 1500 | 93 | 01JAN2008 | Very_Good | 17 | 01JAN2013 | 6557 | 01APR2008 | 01JAN2023 | 215 |
| 6 | Maglev | China | 430 | 1000 | 70 | 2500 | 97 | 01JAN2016 | Excellent | 9 | 01JAN2021 | 3635 | 01APR2016 | 01JAN2031 | 119 |
| 7 | Cable_Car | Switzerland | 25 | 20 | 15 | 80 | 98 | 01JAN2000 | Excellent | 25 | 01JAN2005 | 9479 | 01APR2000 | 01JAN2015 | 311 |
| 8 | Ferry | Norway | 40 | 200 | 100 | 300 | 88 | 01JAN1995 | Good | 30 | 01JAN2000 | 11305 | 01APR1995 | 01JAN2010 | 371 |
| 9 | Electric_Bus | UK | 55 | 100 | 20 | 120 | 89 | 01JAN2018 | Good | 7 | 01JAN2023 | 2904 | 01APR2018 | 01JAN2033 | 95 |
| 10 | Aerial_Tram | Austria | 22 | 25 | 18 | 75 | 94 | 01JAN2003 | Very_Good | 22 | 01JAN2008 | 8383 | 01APR2003 | 01JAN2018 | 275 |
| 11 | Suspended_Monorail | Brazil | 70 | 600 | 35 | 220 | 87 | 01JAN2014 | Good | 11 | 01JAN2019 | 4365 | 01APR2014 | 01JAN2029 | 143 |
| 12 | High_Speed_Rail | Spain | 300 | 1100 | 58 | 1400 | 96 | 01JAN2011 | Excellent | 14 | 01JAN2016 | 5461 | 01APR2011 | 01JAN2026 | 179 |
10.BASIC DESCRIPTIVE STATISTICS
proc mean data=space_inventions;
var Year;
run;
proc means data=space_inventions;
var Year;
run;
PROC MEAN does not exist in SAS. The correct procedure is PROC MEANS.
The MEANS Procedure
| Analysis Variable : Year | ||||
|---|---|---|---|---|
| N | Mean | Std Dev | Minimum | Maximum |
| 12 | 1990.08 | 20.1560202 | 1957.00 | 2015.00 |
/* Note: In practice above there is an Invalid in this code Find it,Correct it and Use it /*
Comments
Post a Comment