259.REAL-WORLD VEHICLES DATASET CREATION AND COMPARISON IN INDIA WITH DATA STEP | PROC FORMAT | PROC PRINT | PROC MEANS | PROC FREQ | PROC SQL | PROC SORT | PROC TRANSPOSE | PROC REPORT | PROC SGPLOT
- Get link
- X
- Other Apps
REAL-WORLD VEHICLES DATASET CREATION AND COMPARISON IN INDIA WITH DATA STEP | PROC FORMAT | PROC PRINT | PROC MEANS | PROC FREQ | PROC SQL | PROC SORT | PROC TRANSPOSE | PROC REPORT | PROC SGPLOT
/*CREATING A DATASET OF REAL-WORLD VEHICLES COMPARISON IN INDIA*/
options nodate nonumber nocenter;
1) Create dataset: vehicles
data vehicles;
length VehicleID 8 Vehicle_Type $25 Manufacturer $25 Region $15 Fuel_Type $12 Owner_Type $12 Emission_Std $8;
format Price_INR comma12. Mileage_kmpl 8.2 Running_km comma12. Year_Mfg 4.;
input VehicleID Vehicle_Type $ Manufacturer $ Year_Mfg Price_INR Mileage_kmpl Running_km Fuel_Type $ Seating Owner_Type $ Region $ Emission_Std $ Battery_kWh;
datalines;
1 Car Maruti 2018 550000 18.5 42000 Petrol 5 Individual North BSIV .
2 Motorcycle Bajaj 2020 75000 65.0 12000 Petrol 2 Individual West BSIV .
3 Scooter TVS 2019 62000 45.0 8000 Petrol 2 Individual South BSIV .
4 Truck Tata 2015 1500000 6.5 120000 Diesel 2 Commercial North BSIII .
5 Bus AshokLeyland 2014 3500000 3.2 250000 Diesel 40 Commercial South BSIII .
6 Auto_Rickshaw Bajaj 2017 65000 35.0 60000 CNG 3 Commercial East BSIV .
7 Electric_Car Tata 2021 1400000 0 15000 Electric 5 Individual West BSVI 22
8 E_Bike Ather 2022 170000 0 5000 Electric 2 Individual South BSVI 3.7
9 Van Maruti_Env 2016 850000 14.0 60000 Diesel 8 Commercial West BSIV .
10 Tractor Mahindra 2013 800000 0 90000 Diesel 2 Agricultural East BSIV .
11 Bicycle Hero 2020 4000 0 300 Individual 1 Individual North . .
12 Luxury_Car BMW 2019 4200000 12.0 25000 Petrol 5 Individual South BSIV .
13 Delivery_Van Tata 2018 720000 11.0 80000 Diesel 3 Commercial West BSIV .
14 Scooter_Hybrid Hero 2020 85000 55.0 9000 Petrol 2 Individual East BSIV .
15 Electric_Scooter Ola 2022 90000 0 3000 Electric 2 Individual North BSVI 2.5
16 Pickup Mahindra 2017 650000 12.5 40000 Diesel 3 Commercial South BSIV .
17 CNG_Car Maruti_CNG 2016 780000 22.0 50000 CNG 5 Individual West BSIV .
18 School_Bus Tata 2015 1800000 3.8 180000 Diesel 45 Commercial North BSIII .
19 Cargo_Truck Volvo 2018 6000000 5.8 100000 Diesel 2 Commercial East BSIV .
20 E_Rickshaw Kinetic 2021 42000 0 15000 Electric 3 Commercial South BSVI 1.5
21 Electric_Bicycle Yulu 2022 12000 0 2000 Electric 1 Individual West BSVI 0.5
22 SUV Hyundai 2020 1800000 14.0 22000 Petrol 7 Individual North BSIV .
;
run;
proc print;run;
Output:
Obs | VehicleID | Vehicle_Type | Manufacturer | Region | Fuel_Type | Owner_Type | Emission_Std | Price_INR | Mileage_kmpl | Running_km | Year_Mfg | Seating | Battery_kWh |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1 | Car | Maruti | North | Petrol | Individual | BSIV | 550,000 | 18.50 | 42,000 | 2018 | 5 | . |
2 | 2 | Motorcycle | Bajaj | West | Petrol | Individual | BSIV | 75,000 | 65.00 | 12,000 | 2020 | 2 | . |
3 | 3 | Scooter | TVS | South | Petrol | Individual | BSIV | 62,000 | 45.00 | 8,000 | 2019 | 2 | . |
4 | 4 | Truck | Tata | North | Diesel | Commercial | BSIII | 1,500,000 | 6.50 | 120,000 | 2015 | 2 | . |
5 | 5 | Bus | AshokLeyland | South | Diesel | Commercial | BSIII | 3,500,000 | 3.20 | 250,000 | 2014 | 40 | . |
6 | 6 | Auto_Rickshaw | Bajaj | East | CNG | Commercial | BSIV | 65,000 | 35.00 | 60,000 | 2017 | 3 | . |
7 | 7 | Electric_Car | Tata | West | Electric | Individual | BSVI | 1,400,000 | 0.00 | 15,000 | 2021 | 5 | 22.0 |
8 | 8 | E_Bike | Ather | South | Electric | Individual | BSVI | 170,000 | 0.00 | 5,000 | 2022 | 2 | 3.7 |
9 | 9 | Van | Maruti_Env | West | Diesel | Commercial | BSIV | 850,000 | 14.00 | 60,000 | 2016 | 8 | . |
10 | 10 | Tractor | Mahindra | East | Diesel | Agricultural | BSIV | 800,000 | 0.00 | 90,000 | 2013 | 2 | . |
11 | 11 | Bicycle | Hero | North | Individual | Individual | 4,000 | 0.00 | 300 | 2020 | 1 | . | |
12 | 12 | Luxury_Car | BMW | South | Petrol | Individual | BSIV | 4,200,000 | 12.00 | 25,000 | 2019 | 5 | . |
13 | 13 | Delivery_Van | Tata | West | Diesel | Commercial | BSIV | 720,000 | 11.00 | 80,000 | 2018 | 3 | . |
14 | 14 | Scooter_Hybrid | Hero | East | Petrol | Individual | BSIV | 85,000 | 55.00 | 9,000 | 2020 | 2 | . |
15 | 15 | Electric_Scooter | Ola | North | Electric | Individual | BSVI | 90,000 | 0.00 | 3,000 | 2022 | 2 | 2.5 |
16 | 16 | Pickup | Mahindra | South | Diesel | Commercial | BSIV | 650,000 | 12.50 | 40,000 | 2017 | 3 | . |
17 | 17 | CNG_Car | Maruti_CNG | West | CNG | Individual | BSIV | 780,000 | 22.00 | 50,000 | 2016 | 5 | . |
18 | 18 | School_Bus | Tata | North | Diesel | Commercial | BSIII | 1,800,000 | 3.80 | 180,000 | 2015 | 45 | . |
19 | 19 | Cargo_Truck | Volvo | East | Diesel | Commercial | BSIV | 6,000,000 | 5.80 | 100,000 | 2018 | 2 | . |
20 | 20 | E_Rickshaw | Kinetic | South | Electric | Commercial | BSVI | 42,000 | 0.00 | 15,000 | 2021 | 3 | 1.5 |
21 | 21 | Electric_Bicycle | Yulu | West | Electric | Individual | BSVI | 12,000 | 0.00 | 2,000 | 2022 | 1 | 0.5 |
22 | 22 | SUV | Hyundai | North | Petrol | Individual | BSIV | 1,800,000 | 14.00 | 22,000 | 2020 | 7 | . |
2) Format variables for reporting
proc format;
value $vtfmt
'Car'='Car'
'Motorcycle'='Motorcycle'
'Scooter'='Scooter'
'Truck'='Truck'
'Bus'='Bus'
'Auto_Rickshaw'='Auto Rickshaw'
'Electric_Car'='Electric Car'
'E_Bike'='E-Bike'
'Van'='Van'
'Tractor'='Tractor'
'Bicycle'='Bicycle'
'Luxury_Car'='Luxury Car'
'Delivery_Van'='Delivery Van'
'Scooter_Hybrid'='Scooter Hybrid'
'Electric_Scooter'='Electric Scooter'
'Pickup'='Pickup'
'CNG_Car'='CNG Car'
'School_Bus'='School Bus'
'Cargo_Truck'='Cargo Truck'
'E_Rickshaw'='E-Rickshaw'
'Electric_Bicycle'='Electric Bicycle'
'SUV'='SUV';
run;
3) Quick look
proc print data=vehicles(obs=10) label noobs;
title "SAMPLE: VEHICLES (FIRST 10)";
run;
title;
Output:
SAMPLE: VEHICLES (FIRST 10)
VehicleID | Vehicle_Type | Manufacturer | Region | Fuel_Type | Owner_Type | Emission_Std | Price_INR | Mileage_kmpl | Running_km | Year_Mfg | Seating | Battery_kWh |
---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Car | Maruti | North | Petrol | Individual | BSIV | 550,000 | 18.50 | 42,000 | 2018 | 5 | . |
2 | Motorcycle | Bajaj | West | Petrol | Individual | BSIV | 75,000 | 65.00 | 12,000 | 2020 | 2 | . |
3 | Scooter | TVS | South | Petrol | Individual | BSIV | 62,000 | 45.00 | 8,000 | 2019 | 2 | . |
4 | Truck | Tata | North | Diesel | Commercial | BSIII | 1,500,000 | 6.50 | 120,000 | 2015 | 2 | . |
5 | Bus | AshokLeyland | South | Diesel | Commercial | BSIII | 3,500,000 | 3.20 | 250,000 | 2014 | 40 | . |
6 | Auto_Rickshaw | Bajaj | East | CNG | Commercial | BSIV | 65,000 | 35.00 | 60,000 | 2017 | 3 | . |
7 | Electric_Car | Tata | West | Electric | Individual | BSVI | 1,400,000 | 0.00 | 15,000 | 2021 | 5 | 22.0 |
8 | E_Bike | Ather | South | Electric | Individual | BSVI | 170,000 | 0.00 | 5,000 | 2022 | 2 | 3.7 |
9 | Van | Maruti_Env | West | Diesel | Commercial | BSIV | 850,000 | 14.00 | 60,000 | 2016 | 8 | . |
10 | Tractor | Mahindra | East | Diesel | Agricultural | BSIV | 800,000 | 0.00 | 90,000 | 2013 | 2 | . |
4) Summary statistics (continuous vars)
proc means data=vehicles n mean median min max std q1 q3;
var Price_INR Mileage_kmpl Running_km Battery_kWh;
class Vehicle_Type;
title "SUMMARY STATISTICS BY VEHICLE TYPE";
run;
title;
Output:
SUMMARY STATISTICS BY VEHICLE TYPE
The MEANS Procedure
Vehicle_Type | N Obs | Variable | N | Mean | Median | Minimum | Maximum | Std Dev | Lower Quartile | Upper Quartile |
---|---|---|---|---|---|---|---|---|---|---|
Auto_Rickshaw | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 65000.00 35.0000000 60000.00 . | 65000.00 35.0000000 60000.00 . | 65000.00 35.0000000 60000.00 . | 65000.00 35.0000000 60000.00 . | . . . . | 65000.00 35.0000000 60000.00 . | 65000.00 35.0000000 60000.00 . |
Bicycle | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 4000.00 0 300.0000000 . | 4000.00 0 300.0000000 . | 4000.00 0 300.0000000 . | 4000.00 0 300.0000000 . | . . . . | 4000.00 0 300.0000000 . | 4000.00 0 300.0000000 . |
Bus | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 3500000.00 3.2000000 250000.00 . | 3500000.00 3.2000000 250000.00 . | 3500000.00 3.2000000 250000.00 . | 3500000.00 3.2000000 250000.00 . | . . . . | 3500000.00 3.2000000 250000.00 . | 3500000.00 3.2000000 250000.00 . |
CNG_Car | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 780000.00 22.0000000 50000.00 . | 780000.00 22.0000000 50000.00 . | 780000.00 22.0000000 50000.00 . | 780000.00 22.0000000 50000.00 . | . . . . | 780000.00 22.0000000 50000.00 . | 780000.00 22.0000000 50000.00 . |
Car | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 550000.00 18.5000000 42000.00 . | 550000.00 18.5000000 42000.00 . | 550000.00 18.5000000 42000.00 . | 550000.00 18.5000000 42000.00 . | . . . . | 550000.00 18.5000000 42000.00 . | 550000.00 18.5000000 42000.00 . |
Cargo_Truck | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 6000000.00 5.8000000 100000.00 . | 6000000.00 5.8000000 100000.00 . | 6000000.00 5.8000000 100000.00 . | 6000000.00 5.8000000 100000.00 . | . . . . | 6000000.00 5.8000000 100000.00 . | 6000000.00 5.8000000 100000.00 . |
Delivery_Van | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 720000.00 11.0000000 80000.00 . | 720000.00 11.0000000 80000.00 . | 720000.00 11.0000000 80000.00 . | 720000.00 11.0000000 80000.00 . | . . . . | 720000.00 11.0000000 80000.00 . | 720000.00 11.0000000 80000.00 . |
E_Bike | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 1 | 170000.00 0 5000.00 3.7000000 | 170000.00 0 5000.00 3.7000000 | 170000.00 0 5000.00 3.7000000 | 170000.00 0 5000.00 3.7000000 | . . . . | 170000.00 0 5000.00 3.7000000 | 170000.00 0 5000.00 3.7000000 |
E_Rickshaw | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 1 | 42000.00 0 15000.00 1.5000000 | 42000.00 0 15000.00 1.5000000 | 42000.00 0 15000.00 1.5000000 | 42000.00 0 15000.00 1.5000000 | . . . . | 42000.00 0 15000.00 1.5000000 | 42000.00 0 15000.00 1.5000000 |
Electric_Bicycle | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 1 | 12000.00 0 2000.00 0.5000000 | 12000.00 0 2000.00 0.5000000 | 12000.00 0 2000.00 0.5000000 | 12000.00 0 2000.00 0.5000000 | . . . . | 12000.00 0 2000.00 0.5000000 | 12000.00 0 2000.00 0.5000000 |
Electric_Car | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 1 | 1400000.00 0 15000.00 22.0000000 | 1400000.00 0 15000.00 22.0000000 | 1400000.00 0 15000.00 22.0000000 | 1400000.00 0 15000.00 22.0000000 | . . . . | 1400000.00 0 15000.00 22.0000000 | 1400000.00 0 15000.00 22.0000000 |
Electric_Scooter | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 1 | 90000.00 0 3000.00 2.5000000 | 90000.00 0 3000.00 2.5000000 | 90000.00 0 3000.00 2.5000000 | 90000.00 0 3000.00 2.5000000 | . . . . | 90000.00 0 3000.00 2.5000000 | 90000.00 0 3000.00 2.5000000 |
Luxury_Car | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 4200000.00 12.0000000 25000.00 . | 4200000.00 12.0000000 25000.00 . | 4200000.00 12.0000000 25000.00 . | 4200000.00 12.0000000 25000.00 . | . . . . | 4200000.00 12.0000000 25000.00 . | 4200000.00 12.0000000 25000.00 . |
Motorcycle | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 75000.00 65.0000000 12000.00 . | 75000.00 65.0000000 12000.00 . | 75000.00 65.0000000 12000.00 . | 75000.00 65.0000000 12000.00 . | . . . . | 75000.00 65.0000000 12000.00 . | 75000.00 65.0000000 12000.00 . |
Pickup | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 650000.00 12.5000000 40000.00 . | 650000.00 12.5000000 40000.00 . | 650000.00 12.5000000 40000.00 . | 650000.00 12.5000000 40000.00 . | . . . . | 650000.00 12.5000000 40000.00 . | 650000.00 12.5000000 40000.00 . |
SUV | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 1800000.00 14.0000000 22000.00 . | 1800000.00 14.0000000 22000.00 . | 1800000.00 14.0000000 22000.00 . | 1800000.00 14.0000000 22000.00 . | . . . . | 1800000.00 14.0000000 22000.00 . | 1800000.00 14.0000000 22000.00 . |
School_Bus | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 1800000.00 3.8000000 180000.00 . | 1800000.00 3.8000000 180000.00 . | 1800000.00 3.8000000 180000.00 . | 1800000.00 3.8000000 180000.00 . | . . . . | 1800000.00 3.8000000 180000.00 . | 1800000.00 3.8000000 180000.00 . |
Scooter | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 62000.00 45.0000000 8000.00 . | 62000.00 45.0000000 8000.00 . | 62000.00 45.0000000 8000.00 . | 62000.00 45.0000000 8000.00 . | . . . . | 62000.00 45.0000000 8000.00 . | 62000.00 45.0000000 8000.00 . |
Scooter_Hybrid | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 85000.00 55.0000000 9000.00 . | 85000.00 55.0000000 9000.00 . | 85000.00 55.0000000 9000.00 . | 85000.00 55.0000000 9000.00 . | . . . . | 85000.00 55.0000000 9000.00 . | 85000.00 55.0000000 9000.00 . |
Tractor | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 800000.00 0 90000.00 . | 800000.00 0 90000.00 . | 800000.00 0 90000.00 . | 800000.00 0 90000.00 . | . . . . | 800000.00 0 90000.00 . | 800000.00 0 90000.00 . |
Truck | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 1500000.00 6.5000000 120000.00 . | 1500000.00 6.5000000 120000.00 . | 1500000.00 6.5000000 120000.00 . | 1500000.00 6.5000000 120000.00 . | . . . . | 1500000.00 6.5000000 120000.00 . | 1500000.00 6.5000000 120000.00 . |
Van | 1 | Price_INR Mileage_kmpl Running_km Battery_kWh | 1 1 1 0 | 850000.00 14.0000000 60000.00 . | 850000.00 14.0000000 60000.00 . | 850000.00 14.0000000 60000.00 . | 850000.00 14.0000000 60000.00 . | . . . . | 850000.00 14.0000000 60000.00 . | 850000.00 14.0000000 60000.00 . |
5) Frequency / distribution (categorical vars)
proc freq data=vehicles;
tables Vehicle_Type Fuel_Type Region Owner_Type Emission_Std / nocum nopercent;
title "FREQUENCIES: CATEGORICAL VARIABLES";
run;
title;
Output:
FREQUENCIES: CATEGORICAL VARIABLES
The FREQ Procedure
Vehicle_Type | Frequency |
---|---|
Auto_Rickshaw | 1 |
Bicycle | 1 |
Bus | 1 |
CNG_Car | 1 |
Car | 1 |
Cargo_Truck | 1 |
Delivery_Van | 1 |
E_Bike | 1 |
E_Rickshaw | 1 |
Electric_Bicycle | 1 |
Electric_Car | 1 |
Electric_Scooter | 1 |
Luxury_Car | 1 |
Motorcycle | 1 |
Pickup | 1 |
SUV | 1 |
School_Bus | 1 |
Scooter | 1 |
Scooter_Hybrid | 1 |
Tractor | 1 |
Truck | 1 |
Van | 1 |
Fuel_Type | Frequency |
---|---|
CNG | 2 |
Diesel | 8 |
Electric | 5 |
Individual | 1 |
Petrol | 6 |
Region | Frequency |
---|---|
East | 4 |
North | 6 |
South | 6 |
West | 6 |
Owner_Type | Frequency |
---|---|
Agricultural | 1 |
Commercial | 9 |
Individual | 12 |
Emission_Std | Frequency |
---|---|
Frequency Missing = 1 | |
BSIII | 3 |
BSIV | 13 |
BSVI | 5 |
6) PROC SQL: Aggregations
proc sql;
create table agg_by_fuel as
select Fuel_Type, count(*) as N, mean(Price_INR) as Avg_Price format=comma12., mean(Mileage_kmpl) as Avg_Mileage format=8.2
from vehicles
group by Fuel_Type
order by Avg_Price desc;
quit;
proc print data=agg_by_fuel noobs;
title "AGGREGATE BY FUEL TYPE";
run;
title;
Output:
AGGREGATE BY FUEL TYPE
Fuel_Type | N | Avg_Price | Avg_Mileage |
---|---|---|---|
Diesel | 8 | 1,977,500 | 7.10 |
Petrol | 6 | 1,128,667 | 34.92 |
CNG | 2 | 422,500 | 28.50 |
Electric | 5 | 342,800 | 0.00 |
Individual | 1 | 4,000 | 0.00 |
7) PROC TRANSPOSE: Price by Year (wide)
proc sort data=vehicles out=_vsorted; by Year_Mfg; run;
proc transpose data=_vsorted out=price_by_year prefix=Price_;
by Year_Mfg notsorted;
id Vehicle_Type;
var Price_INR;
run;
proc print data=price_by_year(obs=10) noobs;
title "TRANSPOSED: PRICE BY YEAR (WIDE)";
run;
title;
Output:
TRANSPOSED: PRICE BY YEAR (WIDE)
Year_Mfg | _NAME_ | Price_Tractor | Price_Bus | Price_Truck | Price_School_Bus | Price_Van | Price_CNG_Car | Price_Auto_Rickshaw | Price_Pickup | Price_Car | Price_Delivery_Van | Price_Cargo_Truck | Price_Scooter | Price_Luxury_Car | Price_Motorcycle | Price_Bicycle | Price_Scooter_Hybrid | Price_SUV | Price_Electric_Car | Price_E_Rickshaw | Price_E_Bike | Price_Electric_Scooter | Price_Electric_Bicycle |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2013 | Price_INR | 800,000 | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |
2014 | Price_INR | . | 3,500,000 | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |
2015 | Price_INR | . | . | 1,500,000 | 1,800,000 | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |
2016 | Price_INR | . | . | . | . | 850,000 | 780,000 | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . |
2017 | Price_INR | . | . | . | . | . | . | 65,000 | 650,000 | . | . | . | . | . | . | . | . | . | . | . | . | . | . |
2018 | Price_INR | . | . | . | . | . | . | . | . | 550,000 | 720,000 | 6,000,000 | . | . | . | . | . | . | . | . | . | . | . |
2019 | Price_INR | . | . | . | . | . | . | . | . | . | . | . | 62,000 | 4,200,000 | . | . | . | . | . | . | . | . | . |
2020 | Price_INR | . | . | . | . | . | . | . | . | . | . | . | . | . | 75,000 | 4,000 | 85,000 | 1,800,000 | . | . | . | . | . |
2021 | Price_INR | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | 1,400,000 | 42,000 | . | . | . |
2022 | Price_INR | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | . | 170,000 | 90,000 | 12,000 |
8) Macro: generate region-wise summary tables
%macro region_report(reg=);
%let reg_trim=%sysfunc(strip(®));
proc sql;
create table region_®_trim as
select Vehicle_Type, count(*) as Count, mean(Price_INR) as Avg_Price format=comma12., mean(Mileage_kmpl) as Avg_Mileage format=8.2
from vehicles
where upcase(Region)=upcase("®_trim")
group by Vehicle_Type;
quit;
proc report data=region_®_trim nowd headline;
column Vehicle_Type Count Avg_Price Avg_Mileage;
define Vehicle_Type / group;
define Count / "COUNT";
define Avg_Price / "AVG PRICE (INR)";
define Avg_Mileage / "AVG MILEAGE";
title "REGION REPORT: ®_trim";
run;
title;
%mend region_report;
%region_report(reg=North);
Output:
REGION REPORT: North
Vehicle_Type | COUNT | AVG PRICE (INR) | AVG MILEAGE |
---|---|---|---|
Bicycle | 1 | 4,000 | 0.00 |
Car | 1 | 550,000 | 18.50 |
Electric_Scooter | 1 | 90,000 | 0.00 |
SUV | 1 | 1,800,000 | 14.00 |
School_Bus | 1 | 1,800,000 | 3.80 |
Truck | 1 | 1,500,000 | 6.50 |
%region_report(reg=South);
Output:
REGION REPORT: South
Vehicle_Type | COUNT | AVG PRICE (INR) | AVG MILEAGE |
---|---|---|---|
Bus | 1 | 3,500,000 | 3.20 |
E_Bike | 1 | 170,000 | 0.00 |
E_Rickshaw | 1 | 42,000 | 0.00 |
Luxury_Car | 1 | 4,200,000 | 12.00 |
Pickup | 1 | 650,000 | 12.50 |
Scooter | 1 | 62,000 | 45.00 |
%region_report(reg=West);
Output:
REGION REPORT: West
Vehicle_Type | COUNT | AVG PRICE (INR) | AVG MILEAGE |
---|---|---|---|
CNG_Car | 1 | 780,000 | 22.00 |
Delivery_Van | 1 | 720,000 | 11.00 |
Electric_Bicycle | 1 | 12,000 | 0.00 |
Electric_Car | 1 | 1,400,000 | 0.00 |
Motorcycle | 1 | 75,000 | 65.00 |
Van | 1 | 850,000 | 14.00 |
9) PROC SGPLOT: visualize price vs mileage (scatter)
proc sgplot data=vehicles;
scatter x=Mileage_kmpl y=Price_INR / group=Fuel_Type markerattrs=(symbol=circlefilled) jitter;
xaxis label="Mileage (kmpl)";
yaxis label="Price (INR)";
title "PRICE vs MILEAGE (COLOURED BY FUEL TYPE)";
run;
title;
Output:
10) PROC SQL: Create a derived table for inexpensive vehicles under 1 Lakh
proc sql;
create table under_1lakh as
select VehicleID, Vehicle_Type, Manufacturer, Price_INR, Fuel_Type, Region
from vehicles
where Price_INR <= 100000
order by Price_INR;
quit;
proc print data=under_1lakh noobs;
title "VEHICLES UNDER INR 1,00,000";
run;
title;
Output:
VEHICLES UNDER INR 1,00,000
VehicleID | Vehicle_Type | Manufacturer | Price_INR | Fuel_Type | Region |
---|---|---|---|---|---|
11 | Bicycle | Hero | 4,000 | Individual | North |
21 | Electric_Bicycle | Yulu | 12,000 | Electric | West |
20 | E_Rickshaw | Kinetic | 42,000 | Electric | South |
3 | Scooter | TVS | 62,000 | Petrol | South |
6 | Auto_Rickshaw | Bajaj | 65,000 | CNG | East |
2 | Motorcycle | Bajaj | 75,000 | Petrol | West |
14 | Scooter_Hybrid | Hero | 85,000 | Petrol | East |
15 | Electric_Scooter | Ola | 90,000 | Electric | North |
11) Cleanup intermediate
proc datasets lib=work nolist;
delete _vsorted;
quit;
- Get link
- X
- Other Apps
Comments
Post a Comment