202.AUDI CARS PERFORMANCE ANALYSIS USING PROC PRINT | PROC MEANS | PROC SQL | PROC FREQ | PROC TRANSPOSE | MACROS | DATA CLEANING | INSIGHTS & TRENDS IN SAS

AUDI CARS PERFORMANCE ANALYSIS USING PROC PRINT | PROC MEANS | PROC SQL | PROC FREQ | PROC TRANSPOSE | MACROS | DATA CLEANING | INSIGHTS & TRENDS IN SAS

/*A unique dataset of different types of Audi cars*/

 Step 1: Create Audi Cars Dataset

A dataset audi_cars with over 15 observations and various columns like:

Model - Audi car model

Type - Car type (SUV, Sedan, Coupe, etc.)

Fuel_Type - Petrol, Diesel, Electric, Hybrid

Horsepower - Engine horsepower

Price_Lakh - Price in Indian Lakhs

Mileage_kmpl - Mileage in km/l

Transmission - Manual/Automatic

Launch_Year - Year launched


data audi_cars;

    infile datalines dsd dlm=' ' truncover;

    length Model $20 Type $15 Fuel_Type $10 Transmission $10;

    input Model :$20. Type :$15. Fuel_Type :$10. Horsepower Price_Lakh Mileage_kmpl 

          Transmission :$10. Launch_Year;

    datalines;

A4 Sedan Petrol 188 45.34 17.42 Automatic 2021

Q5 SUV Diesel 249 62.35 14.9 Automatic 2023

A6 Sedan Petrol 245 65.20 14.5 Automatic 2022

Q7 SUV Petrol 340 84.70 11.21 Automatic 2022

Q3 SUV Diesel 190 44.90 15.2 Automatic 2023

Q8 SUV Petrol 340 135.00 9.8 Automatic 2023

A8 Sedan Petrol 340 134.00 12.0 Automatic 2023

RS5 Coupe Petrol 450 113.00 10.8 Automatic 2022

e-tron SUV Electric 408 123.00 . Automatic 2022

"Q3 Sportback" SUV Petrol 190 51.43 14.93 Automatic 2023

"RS7 Sportback" Sportback Petrol 591 186.00 8.7 Automatic 2023

S5 Coupe Petrol 354 88.00 11.2 Automatic 2022

A3 Sedan Petrol 150 34.00 18.1 Automatic 2021

TT Coupe Petrol 230 79.00 14.3 Automatic 2021

"e-tron GT" Sedan Electric 530 170.00 . Automatic 2023

"RS Q8" SUV Petrol 600 240.00 8.3 Automatic 2024

;

run;

proc print ; run;

Output:

Obs Model Type Fuel_Type Transmission Horsepower Price_Lakh Mileage_kmpl Launch_Year
1 A4 Sedan Petrol Automatic 188 45.34 17.42 2021
2 Q5 SUV Diesel Automatic 249 62.35 14.90 2023
3 A6 Sedan Petrol Automatic 245 65.20 14.50 2022
4 Q7 SUV Petrol Automatic 340 84.70 11.21 2022
5 Q3 SUV Diesel Automatic 190 44.90 15.20 2023
6 Q8 SUV Petrol Automatic 340 135.00 9.80 2023
7 A8 Sedan Petrol Automatic 340 134.00 12.00 2023
8 RS5 Coupe Petrol Automatic 450 113.00 10.80 2022
9 e-tron SUV Electric Automatic 408 123.00 . 2022
10 Q3 Sportback SUV Petrol Automatic 190 51.43 14.93 2023
11 RS7 Sportback Sportback Petrol Automatic 591 186.00 8.70 2023
12 S5 Coupe Petrol Automatic 354 88.00 11.20 2022
13 A3 Sedan Petrol Automatic 150 34.00 18.10 2021
14 TT Coupe Petrol Automatic 230 79.00 14.30 2021
15 e-tron GT Sedan Electric Automatic 530 170.00 . 2023
16 RS Q8 SUV Petrol Automatic 600 240.00 8.30 2024


Step 2: Display the Dataset - PROC PRINT

title "Audi Cars Dataset - All Observations";

proc print data=audi_cars noobs;

run;

Output:

Audi Cars Dataset - All Observations

Model Type Fuel_Type Transmission Horsepower Price_Lakh Mileage_kmpl Launch_Year
A4 Sedan Petrol Automatic 188 45.34 17.42 2021
Q5 SUV Diesel Automatic 249 62.35 14.90 2023
A6 Sedan Petrol Automatic 245 65.20 14.50 2022
Q7 SUV Petrol Automatic 340 84.70 11.21 2022
Q3 SUV Diesel Automatic 190 44.90 15.20 2023
Q8 SUV Petrol Automatic 340 135.00 9.80 2023
A8 Sedan Petrol Automatic 340 134.00 12.00 2023
RS5 Coupe Petrol Automatic 450 113.00 10.80 2022
e-tron SUV Electric Automatic 408 123.00 . 2022
Q3 Sportback SUV Petrol Automatic 190 51.43 14.93 2023
RS7 Sportback Sportback Petrol Automatic 591 186.00 8.70 2023
S5 Coupe Petrol Automatic 354 88.00 11.20 2022
A3 Sedan Petrol Automatic 150 34.00 18.10 2021
TT Coupe Petrol Automatic 230 79.00 14.30 2021
e-tron GT Sedan Electric Automatic 530 170.00 . 2023
RS Q8 SUV Petrol Automatic 600 240.00 8.30 2024

Step 3: Summary Statistics - PROC MEANS

title "Summary of Price, Horsepower, and Mileage";

proc means data=audi_cars mean min max std;

    var Price_Lakh Horsepower Mileage_kmpl;

run;

Output:

Summary of Price, Horsepower, and Mileage

The MEANS Procedure

Variable Mean Minimum Maximum Std Dev
Price_Lakh
Horsepower
Mileage_kmpl
103.4950000
337.1875000
12.9542857
34.0000000
150.0000000
8.3000000
240.0000000
600.0000000
18.1000000
58.2900693
145.3970283
3.0975939

Step 4: Count Analysis - PROC FREQ

A. Fuel Type Distribution

title "Fuel Type Frequency";

proc freq data=audi_cars;

    tables Fuel_Type;

run;

Output:

Fuel Type Frequency

The FREQ Procedure

Fuel_Type Frequency Percent Cumulative
Frequency
Cumulative
Percent
Diesel 2 12.50 2 12.50
Electric 2 12.50 4 25.00
Petrol 12 75.00 16 100.00

B. Car Type Distribution

title "Type Distribution of Audi Cars";

proc freq data=audi_cars;

    tables Type;

run;

Output:

Type Distribution of Audi Cars

The FREQ Procedure

Type Frequency Percent Cumulative
Frequency
Cumulative
Percent
Coupe 3 18.75 3 18.75
SUV 7 43.75 10 62.50
Sedan 5 31.25 15 93.75
Sportback 1 6.25 16 100.00

Step 5: Sort Dataset - PROC SORT

title "Sorted Audi Cars by Horsepower";

proc sort data=audi_cars out=sorted_cars;

    by descending Horsepower;

run;

proc print data=sorted_cars (obs=5);

    title "Top 5 Most Powerful Audi Cars";

run;

Output:

Top 5 Most Powerful Audi Cars

Obs Model Type Fuel_Type Transmission Horsepower Price_Lakh Mileage_kmpl Launch_Year
1 RS Q8 SUV Petrol Automatic 600 240 8.3 2024
2 RS7 Sportback Sportback Petrol Automatic 591 186 8.7 2023
3 e-tron GT Sedan Electric Automatic 530 170 . 2023
4 RS5 Coupe Petrol Automatic 450 113 10.8 2022
5 e-tron SUV Electric Automatic 408 123 . 2022


Step 6: Transpose Data - PROC TRANSPOSE

title "Transpose: Mileage and Price by Model";

proc transpose data=audi_cars out=transposed prefix=Stats_;

    id Model;

    var Mileage_kmpl Price_Lakh;

run;

proc print data=transposed;

run;

Output:

Transpose: Mileage and Price by Model

Obs _NAME_ Stats_A4 Stats_Q5 Stats_A6 Stats_Q7 Stats_Q3 Stats_Q8 Stats_A8 Stats_RS5 Stats_e_tron Stats_Q3_Sportback Stats_RS7_Sportback Stats_S5 Stats_A3 Stats_TT Stats_e_tron_GT Stats_RS_Q8
1 Mileage_kmpl 17.42 14.90 14.5 11.21 15.2 9.8 12 10.8 . 14.93 8.7 11.2 18.1 14.3 . 8.3
2 Price_Lakh 45.34 62.35 65.2 84.70 44.9 135.0 134 113.0 123 51.43 186.0 88.0 34.0 79.0 170 240.0


Step 7: SQL Procedures - PROC SQL

A. Filter Expensive Cars

proc sql;

    title "Audi Cars Above 100 Lakhs";

    select Model, Price_Lakh

    from audi_cars

    where Price_Lakh > 100;

quit;

Output:

Audi Cars Above 100 Lakhs

Model Price_Lakh
Q8 135
A8 134
RS5 113
e-tron 123
RS7 Sportback 186
e-tron GT 170
RS Q8 240

B. Average Mileage per Type

proc sql;

    title "Average Mileage by Car Type";

    select Type, avg(Mileage_kmpl) as Avg_Mileage

    from audi_cars

    group by Type;

quit;

Output:

Average Mileage by Car Type

Type Avg_Mileage
Coupe 12.1
SUV 12.39
Sedan 15.505
Sportback 8.7


Step 8: Using Macros to Automate

%macro summarize(var);

    title "Summary Statistics for &var";

    proc means data=audi_cars mean min max;

        var &var;

    run;

%mend summarize;


/* Call macro for Horsepower */

%summarize(Horsepower)

Output:

Summary Statistics for Horsepower

The MEANS Procedure

Analysis Variable : Horsepower
Mean Minimum Maximum
337.1875000 150.0000000 600.0000000

/* Call macro for Price */

%summarize(Price_Lakh)

Output:

Summary Statistics for Price_Lakh

The MEANS Procedure

Analysis Variable : Price_Lakh
Mean Minimum Maximum
103.4950000 34.0000000 240.0000000

Step 9: Cars Launched After 2022

proc sql;

    title "Audi Cars Launched After 2022";

    select Model, Launch_Year, Price_Lakh

    from audi_cars

    where Launch_Year > 2022;

quit;

Output:

Audi Cars Launched After 2022

Model Launch_Year Price_Lakh
Q5 2023 62.35
Q3 2023 44.9
Q8 2023 135
A8 2023 134
Q3 Sportback 2023 51.43
RS7 Sportback 2023 186
e-tron GT 2023 170
RS Q8 2024 240

Step 10: Identify Electric Cars

proc sql;

    title "List of Electric Audi Cars";

    select Model, Horsepower, Price_Lakh

    from audi_cars

    where Fuel_Type = "Electric";

quit;

Output:

List of Electric Audi Cars

Model Horsepower Price_Lakh
e-tron 408 123
e-tron GT 530 170

Step 11: Correlation Between Price and Horsepower

title "Correlation Analysis";

proc corr data=audi_cars;

    var Horsepower Price_Lakh;

run;

Output:

Correlation Analysis

The CORR Procedure

2 Variables: Horsepower Price_Lakh

Simple Statistics
Variable N Mean Std Dev Sum Minimum Maximum
Horsepower 16 337.18750 145.39703 5395 150.00000 600.00000
Price_Lakh 16 103.49500 58.29007 1656 34.00000 240.00000

Pearson Correlation Coefficients, N = 16
Prob > |r| under H0: Rho=0
  Horsepower Price_Lakh
Horsepower
1.00000
 
0.94165
<.0001
Price_Lakh
0.94165
<.0001
1.00000
 

Step 12: Group Statistics - PROC MEANS + CLASS

title "Average Stats by Transmission Type";

proc means data=audi_cars mean max;

    class Transmission;

    var Price_Lakh Horsepower Mileage_kmpl;

run;

Output:

Average Stats by Transmission Type

The MEANS Procedure

Transmission N Obs Variable Mean Maximum
Automatic 16
Price_Lakh
Horsepower
Mileage_kmpl
103.4950000
337.1875000
12.9542857
240.0000000
600.0000000
18.1000000

Step 13: Conditional Column - Creating a Flag

data audi_cars_flagged;

    retain Model Type Fuel_Type Transmission Horsepower Price_Lakh Mileage_kmpl Launch_Year ;

    length Luxury_Flag $20.;

    set audi_cars;

    if Price_Lakh > 100 then Luxury_Flag = "Luxury";

    else Luxury_Flag = "Standard";

run;

proc print;run;

Output:

Obs Model Type Fuel_Type Transmission Horsepower Price_Lakh Mileage_kmpl Launch_Year Luxury_Flag
1 A4 Sedan Petrol Automatic 188 45.34 17.42 2021 Standard
2 Q5 SUV Diesel Automatic 249 62.35 14.90 2023 Standard
3 A6 Sedan Petrol Automatic 245 65.20 14.50 2022 Standard
4 Q7 SUV Petrol Automatic 340 84.70 11.21 2022 Standard
5 Q3 SUV Diesel Automatic 190 44.90 15.20 2023 Standard
6 Q8 SUV Petrol Automatic 340 135.00 9.80 2023 Luxury
7 A8 Sedan Petrol Automatic 340 134.00 12.00 2023 Luxury
8 RS5 Coupe Petrol Automatic 450 113.00 10.80 2022 Luxury
9 e-tron SUV Electric Automatic 408 123.00 . 2022 Luxury
10 Q3 Sportback SUV Petrol Automatic 190 51.43 14.93 2023 Standard
11 RS7 Sportback Sportback Petrol Automatic 591 186.00 8.70 2023 Luxury
12 S5 Coupe Petrol Automatic 354 88.00 11.20 2022 Standard
13 A3 Sedan Petrol Automatic 150 34.00 18.10 2021 Standard
14 TT Coupe Petrol Automatic 230 79.00 14.30 2021 Standard
15 e-tron GT Sedan Electric Automatic 530 170.00 . 2023 Luxury
16 RS Q8 SUV Petrol Automatic 600 240.00 8.30 2024 Luxury

proc freq data=audi_cars_flagged;

    title "Luxury vs Standard Classification";

    tables Luxury_Flag;

run;

Output:

Luxury vs Standard Classification

The FREQ Procedure

Luxury_Flag Frequency Percent Cumulative
Frequency
Cumulative
Percent
Luxury 7 43.75 7 43.75
Standard 9 56.25 16 100.00

Step 14: Exporting to Excel

proc export data=audi_cars

    outfile="audi_cars.xlsx"

    dbms=xlsx

    replace;

run;

Log:

NOTE: The export data set has 16 observations and 8 variables.
NOTE: "C:\sas folder\SASFoundation\9.4\audi_cars.xlsx" file was successfully created.
NOTE: PROCEDURE EXPORT used (Total process time):
      real time           0.71 seconds
      cpu time            0.01 seconds




To Visit My Previous Sas Project 11-20 Questions:Click Here
To Visit My Previous %Let %Put %Eval In Sas:Click Here
To Visit My Previous Creating Assessing Cleaning Manipulation In Sas:Click Here
To Visit My Previous Proc Contents In Sas:Click Here





--->PLEASE FOLLOW OUR BLOG FOR MORE INFORMATION.
--->PLEASE DO COMMENTS AND SHARE OUR BLOG.

PLEASE FOLLOW OUR TELEGRAM CHANNEL CLICK HERE

PLEASE FOLLOW OUR FACEBOOK PAGE  CLICK HERE

PLEASE FOLLOW OUR INSTAGRAM PAGE CLICK HERE


Comments