322.ADVANCED CAR COMPANIES SALES AND PERFORMANCE DATASET CREATION AND ANALYSIS USING PROC SQL | PROC MEANS | PROC STANDARD | PROC SGPLOT | MACROS | INTCK | INTNX

ADVANCED CAR COMPANIES SALES AND PERFORMANCE DATASET CREATION AND ANALYSIS USING PROC SQL | PROC MEANS | PROC STANDARD | PROC SGPLOT | MACROS | INTCK | INTNX

options nocenter;

1. CREATE RAW DATASET WITH DATE VARIABLES AND FORMATS 

data work.cars_raw;

    length Brand $15 Model $20 Engine_Type $10;

    format Launch_Date Review_Date Analysis_Date Next_Service_Date Five_Year_Anniv date9.;

    format Price comma10.2;

    input Brand $ Model $ Engine_Type $

          Sales_2024 Mileage Price Safety_Rating

          Launch_Date :date9. Review_Date :date9.;

    

    /* Set a common analysis date (end of 2024) */

    Analysis_Date = '31DEC2024'd;


    /* Date-based derived variables using INTCK and INTNX */

    Years_Since_Launch = intck('year', Launch_Date, Analysis_Date);

    Months_Between_Launch_Review = intck('month', Launch_Date, Review_Date);


    /* 5-year anniversary from launch and next service due 6 months after last review */

    Five_Year_Anniv   = intnx('year', Launch_Date, 5, 'same');

    Next_Service_Date = intnx('month', Review_Date, 6, 'same');

datalines;

Toyota Corolla Petrol 980000 18.5 18000 4.5 15JAN2018 10MAR2024

Honda City Petrol 620000 17.8 16000 4.3 10JUN2019 05FEB2024

Maruti Swift Petrol 850000 21.1 9000 4.2 01APR2017 20JAN2024

Hyundai Creta Diesel 740000 19.5 20000 4.6 20AUG2020 15MAR2024

Tata NexonEV EV 210000 320.0 22000 4.7 05DEC2021 01APR2024

Kia Seltos Diesel 530000 18.0 19000 4.4 12SEP2019 12FEB2024

Mahindra XUV700 Diesel 350000 16.5 25000 4.8 01NOV2021 28APR2024

Skoda Slavia Petrol 90000 18.7 23000 4.4 15MAR2022 10MAY2024

Volkswagen Virtus Petrol 80000 18.9 24000 4.3 20APR2022 18MAY2024

MG Hector Petrol 260000 15.8 21000 4.2 10JAN2020 22MAR2024

Renault Kiger Petrol 150000 19.0 11000 4.0 05FEB2021 10FEB2024

Hyundai Ioniq5 EV 30000 450.0 45000 4.9 01JUL2023 01JUN2024

;

run;

proc print data=work.cars_raw;

run;

OUTPUT:

ObsBrandModelEngine_TypeLaunch_DateReview_DateAnalysis_DateNext_Service_DateFive_Year_AnnivPriceSales_2024MileageSafety_RatingYears_Since_LaunchMonths_Between_Launch_Review
1ToyotaCorollaPetrol15JAN201810MAR202431DEC202410SEP202415JAN202318,000.0098000018.54.5674
2HondaCityPetrol10JUN201905FEB202431DEC202405AUG202410JUN202416,000.0062000017.84.3556
3MarutiSwiftPetrol01APR201720JAN202431DEC202420JUL202401APR20229,000.0085000021.14.2781
4HyundaiCretaDiesel20AUG202015MAR202431DEC202415SEP202420AUG202520,000.0074000019.54.6443
5TataNexonEVEV05DEC202101APR202431DEC202401OCT202405DEC202622,000.00210000320.04.7328
6KiaSeltosDiesel12SEP201912FEB202431DEC202412AUG202412SEP202419,000.0053000018.04.4553
7MahindraXUV700Diesel01NOV202128APR202431DEC202428OCT202401NOV202625,000.0035000016.54.8329
8SkodaSlaviaPetrol15MAR202210MAY202431DEC202410NOV202415MAR202723,000.009000018.74.4226
9VolkswagenVirtusPetrol20APR202218MAY202431DEC202418NOV202420APR202724,000.008000018.94.3225
10MGHectorPetrol10JAN202022MAR202431DEC202422SEP202410JAN202521,000.0026000015.84.2450
11RenaultKigerPetrol05FEB202110FEB202431DEC202410AUG202405FEB202611,000.0015000019.04.0336
12HyundaiIoniq5EV01JUL202301JUN202431DEC202401DEC202401JUL202845,000.0030000450.04.9111


2. PROC SQL SUMMARY BY BRAND AND ENGINE TYPE 

proc sql;

    create table work.cars_brand_summary as

    select Brand,

           Engine_Type,

           count(*)             as Models_Count,

           sum(Sales_2024)      as Total_Sales_2024,

           mean(Mileage)        as Avg_Mileage,

           mean(Price)          as Avg_Price,

           mean(Safety_Rating)  as Avg_Safety_Rating

    from work.cars_raw

    group by Brand, Engine_Type

    order by Total_Sales_2024 desc;

quit;

proc print data=work.cars_brand_summary;

run;

OUTPUT:

ObsBrandEngine_TypeModels_CountTotal_Sales_2024Avg_MileageAvg_PriceAvg_Safety_Rating
1ToyotaPetrol198000018.5180004.5
2MarutiPetrol185000021.190004.2
3HyundaiDiesel174000019.5200004.6
4HondaPetrol162000017.8160004.3
5KiaDiesel153000018.0190004.4
6MahindraDiesel135000016.5250004.8
7MGPetrol126000015.8210004.2
8TataEV1210000320.0220004.7
9RenaultPetrol115000019.0110004.0
10SkodaPetrol19000018.7230004.4
11VolkswagenPetrol18000018.9240004.3
12HyundaiEV130000450.0450004.9


3. MACRO FOR SALES RANKING USING PROC SQL (MODEL LEVEL) 

%macro rank_sales(in=work.cars_raw, out=work.cars_ranked);

    proc sql;

        create table &out as

        select a.*,

               /* Rank based on descending Sales_2024 using a correlated subquery */

               (select count(*) 

                from &in b

                where b.Sales_2024 >= a.Sales_2024) as Sales_Rank

        from &in as a

        order by Sales_2024 desc;

    quit;

proc print data=&out;

run;

%mend rank_sales;


%rank_sales();

OUTPUT:

ObsBrandModelEngine_TypeLaunch_DateReview_DateAnalysis_DateNext_Service_DateFive_Year_AnnivPriceSales_2024MileageSafety_RatingYears_Since_LaunchMonths_Between_Launch_ReviewSales_Rank
1ToyotaCorollaPetrol15JAN201810MAR202431DEC202410SEP202415JAN202318,000.0098000018.54.56741
2MarutiSwiftPetrol01APR201720JAN202431DEC202420JUL202401APR20229,000.0085000021.14.27812
3HyundaiCretaDiesel20AUG202015MAR202431DEC202415SEP202420AUG202520,000.0074000019.54.64433
4HondaCityPetrol10JUN201905FEB202431DEC202405AUG202410JUN202416,000.0062000017.84.35564
5KiaSeltosDiesel12SEP201912FEB202431DEC202412AUG202412SEP202419,000.0053000018.04.45535
6MahindraXUV700Diesel01NOV202128APR202431DEC202428OCT202401NOV202625,000.0035000016.54.83296
7MGHectorPetrol10JAN202022MAR202431DEC202422SEP202410JAN202521,000.0026000015.84.24507
8TataNexonEVEV05DEC202101APR202431DEC202401OCT202405DEC202622,000.00210000320.04.73288
9RenaultKigerPetrol05FEB202110FEB202431DEC202410AUG202405FEB202611,000.0015000019.04.03369
10SkodaSlaviaPetrol15MAR202210MAY202431DEC202410NOV202415MAR202723,000.009000018.74.422610
11VolkswagenVirtusPetrol20APR202218MAY202431DEC202418NOV202420APR202724,000.008000018.94.322511
12HyundaiIoniq5EV01JUL202301JUN202431DEC202401DEC202401JUL202845,000.0030000450.04.911112


4. PROC MEANS: OVERALL NUMERIC SUMMARY 

proc means data=work.cars_ranked n mean std min max maxdec=2;

    var Sales_2024 Mileage Price Safety_Rating Years_Since_Launch;

run;

OUTPUT:

The MEANS Procedure

VariableNMeanStd DevMinimumMaximum
Sales_2024
Mileage
Price
Safety_Rating
Years_Since_Launch
12
12
12
12
12
407500.00
79.48
21083.33
4.44
3.75
326861.80
145.38
8989.47
0.27
1.76
30000.00
15.80
9000.00
4.00
1.00
980000.00
450.00
45000.00
4.90
7.00

5. PROC STANDARD: STANDARDIZE SALES, MILEAGE, AND PRICE 

proc standard data=work.cars_ranked mean=0 std=1 out=work.cars_standardized;

    var Sales_2024 Mileage Price;

run;

proc print data=work.cars_standardized;

     var Sales_2024 Mileage Price;

run;

OUTPUT:

ObsSales_2024MileagePrice
11.75150-0.41948-0.34
21.35378-0.40159-1.34
31.01725-0.41260-0.12
40.65012-0.42429-0.57
50.37478-0.42292-0.23
6-0.17592-0.433230.44
7-0.45126-0.43805-0.01
8-0.604231.654410.10
9-0.78779-0.41604-1.12
10-0.97136-0.418100.21
11-1.00195-0.416730.32
12-1.154922.548622.66

6. MACRO FOR AUTOMATED SUMMARIES BY ANY CLASS VARIABLE 

%macro summary_by(classvar=);

    title "SUMMARY OF CAR METRICS BY &classvar";

    proc means data=work.cars_ranked mean std min max maxdec=2;

        class &classvar;

        var Sales_2024 Mileage Price Safety_Rating;

    run;

    title;

%mend summary_by;


%summary_by(classvar=Engine_Type);

OUTPUT:

SUMMARY OF CAR METRICS BY Engine_Type

The MEANS Procedure

Engine_TypeN ObsVariableMeanStd DevMinimumMaximum
Diesel3
Sales_2024
Mileage
Price
Safety_Rating
540000.00
18.00
21333.33
4.60
195192.21
1.50
3214.55
0.20
350000.00
16.50
19000.00
4.40
740000.00
19.50
25000.00
4.80
EV2
Sales_2024
Mileage
Price
Safety_Rating
120000.00
385.00
33500.00
4.80
127279.22
91.92
16263.46
0.14
30000.00
320.00
22000.00
4.70
210000.00
450.00
45000.00
4.90
Petrol7
Sales_2024
Mileage
Price
Safety_Rating
432857.14
18.54
17428.57
4.27
378669.35
1.58
5798.19
0.16
80000.00
15.80
9000.00
4.00
980000.00
21.10
24000.00
4.50

%summary_by(classvar=Brand);

OUTPUT:

SUMMARY OF CAR METRICS BY Brand

The MEANS Procedure

BrandN ObsVariableMeanStd DevMinimumMaximum
Honda1
Sales_2024
Mileage
Price
Safety_Rating
620000.00
17.80
16000.00
4.30
.
.
.
.
620000.00
17.80
16000.00
4.30
620000.00
17.80
16000.00
4.30
Hyundai2
Sales_2024
Mileage
Price
Safety_Rating
385000.00
234.75
32500.00
4.75
502045.81
304.41
17677.67
0.21
30000.00
19.50
20000.00
4.60
740000.00
450.00
45000.00
4.90
Kia1
Sales_2024
Mileage
Price
Safety_Rating
530000.00
18.00
19000.00
4.40
.
.
.
.
530000.00
18.00
19000.00
4.40
530000.00
18.00
19000.00
4.40
MG1
Sales_2024
Mileage
Price
Safety_Rating
260000.00
15.80
21000.00
4.20
.
.
.
.
260000.00
15.80
21000.00
4.20
260000.00
15.80
21000.00
4.20
Mahindra1
Sales_2024
Mileage
Price
Safety_Rating
350000.00
16.50
25000.00
4.80
.
.
.
.
350000.00
16.50
25000.00
4.80
350000.00
16.50
25000.00
4.80
Maruti1
Sales_2024
Mileage
Price
Safety_Rating
850000.00
21.10
9000.00
4.20
.
.
.
.
850000.00
21.10
9000.00
4.20
850000.00
21.10
9000.00
4.20
Renault1
Sales_2024
Mileage
Price
Safety_Rating
150000.00
19.00
11000.00
4.00
.
.
.
.
150000.00
19.00
11000.00
4.00
150000.00
19.00
11000.00
4.00
Skoda1
Sales_2024
Mileage
Price
Safety_Rating
90000.00
18.70
23000.00
4.40
.
.
.
.
90000.00
18.70
23000.00
4.40
90000.00
18.70
23000.00
4.40
Tata1
Sales_2024
Mileage
Price
Safety_Rating
210000.00
320.00
22000.00
4.70
.
.
.
.
210000.00
320.00
22000.00
4.70
210000.00
320.00
22000.00
4.70
Toyota1
Sales_2024
Mileage
Price
Safety_Rating
980000.00
18.50
18000.00
4.50
.
.
.
.
980000.00
18.50
18000.00
4.50
980000.00
18.50
18000.00
4.50
Volkswagen1
Sales_2024
Mileage
Price
Safety_Rating
80000.00
18.90
24000.00
4.30
.
.
.
.
80000.00
18.90
24000.00
4.30
80000.00
18.90
24000.00
4.30

7. PROC SGPLOT VISUALIZATIONS 

/* Bar chart: Brand vs Sales_2024 */

proc sgplot data=work.cars_ranked;

    vbar Brand / response=Sales_2024 datalabel;

    xaxis discreteorder=data label="Brand";

    yaxis label="Sales in 2024 (Units)";

run;

OUTPUT:

The SGPlot Procedure


/* Scatter plot: Mileage vs Price, colored by Engine_Type */

proc sgplot data=work.cars_ranked;

    scatter x=Mileage y=Price / group=Engine_Type datalabel=Model;

    xaxis label="Mileage (km/L or km/charge)";

    yaxis label="Price";

run;

OUTPUT:

The SGPlot Procedure



To Visit My Previous Online Streaming Flatform Dataset:Click Here
To Visit My Previous Statistical Evaluation Of Clinical Trials:Click Here
To Visit My Previous Unlocking Retail Insights Dataset:Click Here
To Visit My Previous Sas Interview Questions-1:Click Here  



Follow Us On : 


 


--- FOLLOW OUR BLOG FOR MORE INFORMATION.

--->PLEASE DO COMMENTS AND SHARE OUR BLOG.






Comments

Popular posts from this blog

409.Can We Build a Reliable Emergency Services Analytics & Fraud Detection System in SAS While Identifying and Fixing Intentional Errors?

397.If a satellite has excellent signal strength but very high latency, can it still deliver good quality communication? Why or why not?A Sas Study

401.How Efficient Are Global Data Centers? A Complete SAS Analytics Study