154.​UNVEILING URBAN TRAFFIC DYNAMICS: A COMPREHENSIVE ANALYSIS USING SAS PROCEDURES | PROC CONTENTS | PROC PRINT | PROC MEANS | PROC FREQ | PROC FORMAT | PROC REPORT | PROC SGPLOT | PROC SQL | PROC UNIVARIATE | PROC CORR​

UNVEILING URBAN TRAFFIC DYNAMICS: A COMPREHENSIVE ANALYSIS USING SAS PROCEDURES | PROC CONTENTS | PROC PRINT | PROC MEANS | PROC FREQ | PROC FORMAT | PROC REPORT | PROC SGPLOT | PROC SQL | PROC UNIVARIATE | PROC CORR


 /*Create a unique dataset centered around urban traffic patterns and apply various SAS procedures to analyze it.*/


Dataset Overview: Urban Traffic Patterns

Dataset Name: urban_traffic_data

Variables:

Intersection_ID (Character): Unique identifier for each intersection (e.g., "INT001").

Date (Date): Date of observation.

Time (Time): Time of observation.

Vehicle_Count (Numeric): Number of vehicles passing through the intersection during the observed time interval.

Average_Speed (Numeric): Average speed of vehicles in km/h.

Accident_Occurred (Character): Indicates if an accident occurred ("Yes"/"No").

Weather_Condition (Character): Weather during observation ("Clear", "Rainy", "Foggy", etc.).

Traffic_Signal_Status (Character): Status of the traffic signal ("Operational", "Flashing", "Out of Order").


Creating the Dataset in SAS

data urban_traffic_data;

    format Date date9. Time time5.;

    input Intersection_ID $ Date :date9. Time :time5. Vehicle_Count Average_Speed Accident_Occurred $ Weather_Condition $ Traffic_Signal_Status $;

    datalines;

INT001 01JAN2025 08:00 120 45 No Clear Operational

INT002 01JAN2025 08:00 95 50 No Rainy Operational

INT003 01JAN2025 08:00 110 40 Yes Foggy Flashing

INT001 01JAN2025 09:00 130 47 No Clear Operational

INT002 01JAN2025 09:00 100 52 No Rainy Operational

INT003 01JAN2025 09:00 115 42 No Foggy Flashing

;

run;

proc print data=urban_traffic_data (obs=10);

    title "Sample Observations from Urban Traffic Data";

run;

Output:

                                                    Sample Observations from Urban Traffic Data

Obs Date Time Intersection_ID Vehicle_Count Average_Speed Accident_Occurred Weather_Condition Traffic_Signal_Status
1 01JAN2025 8:00 INT001 120 45 No Clear Operational
2 01JAN2025 8:00 INT002 95 50 No Rainy Operational
3 01JAN2025 8:00 INT003 110 40 Yes Foggy Flashing
4 01JAN2025 9:00 INT001 130 47 No Clear Operational
5 01JAN2025 9:00 INT002 100 52 No Rainy Operational
6 01JAN2025 9:00 INT003 115 42 No Foggy Flashing


Applying SAS Procedures

1. PROC CONTENTS: Understanding the Dataset Structure

proc contents data=urban_traffic_data;

run;

Output:

                                                                The CONTENTS Procedure

Data Set Name WORK.URBAN_TRAFFIC_DATA Observations 6
Member Type DATA Variables 8
Engine V9 Indexes 0
Created 14/09/2015 00:37:18 Observation Length 72
Last Modified 14/09/2015 00:37:18 Deleted Observations 0
Protection   Compressed NO
Data Set Type   Sorted NO
Label      
Data Representation WINDOWS_64    
Encoding wlatin1 Western (Windows)    


Engine/Host Dependent Information
Data Set Page Size 65536
Number of Data Set Pages 1
First Data Page 1
Max Obs per Page 908
Obs in First Data Page 6
Number of Data Set Repairs 0
ExtendObsCounter YES
Filename C:\Users\Lenovo\AppData\Local\Temp\SAS Temporary Files\_TD11628_DESKTOP-QFAA4KV_\urban_traffic_data.sas7bdat
Release Created 9.0401M2
Host Created X64_8HOME


Alphabetic List of Variables and Attributes
# Variable Type Len Format
6 Accident_Occurred Char 8  
5 Average_Speed Num 8  
1 Date Num 8 DATE9.
3 Intersection_ID Char 8  
2 Time Num 8 TIME5.
8 Traffic_Signal_Status Char 15  
4 Vehicle_Count Num 8  
7 Weather_Condition Char 8  


/*This procedure provides metadata about the dataset, including variable types, lengths, and formats.*/


2. PROC MEANS: Descriptive Statistics

proc means data=urban_traffic_data n mean std min max;

    var Vehicle_Count Average_Speed;

run;

Output:

                                                             The MEANS Procedure

Variable N Mean Std Dev Minimum Maximum
Vehicle_Count
Average_Speed
6
6
111.6666667
46.0000000
12.9099445
4.6043458
95.0000000
40.0000000
130.0000000
52.0000000

/*Calculates basic statistics for Vehicle_Count and Average_Speed.*/


3. PROC FREQ: Frequency Analysis

proc freq data=urban_traffic_data;

    tables Accident_Occurred Weather_Condition Traffic_Signal_Status;

run;

Output:

                                                                    The FREQ Procedure

Accident_Occurred Frequency Percent Cumulative
Frequency
Cumulative
Percent
No 5 83.33 5 83.33
Yes 1 16.67 6 100.00


Weather_Condition Frequency Percent Cumulative
Frequency
Cumulative
Percent
Clear 2 33.33 2 33.33
Foggy 2 33.33 4 66.67
Rainy 2 33.33 6 100.00


Traffic_Signal_Status Frequency Percent Cumulative
Frequency
Cumulative
Percent
Flashing 2 33.33 2 33.33
Operational 4 66.67 6 100.00

/*Analyzes the frequency of accidents, weather conditions, and signal statuses.*/


4. PROC FORMAT: Creating Custom Formats

proc format;

    value $accident_fmt

        'Yes' = 'Accident'

        'No'  = 'No Accident';

    value $weather_fmt

        'Clear' = 'Clear Weather'

        'Rainy' = 'Rainy Weather'

        'Foggy' = 'Foggy Conditions';

run;

/*Defines custom formats for better readability.*/


5. PROC REPORT: Customized Reporting

proc report data=urban_traffic_data nowd;

    columns Intersection_ID Date Vehicle_Count Average_Speed Accident_Occurred;

    define Intersection_ID / group;

    define Date / group;

    define Vehicle_Count / analysis sum;

    define Average_Speed / analysis mean;

    define Accident_Occurred / display format=$accident_fmt.;

    title "Traffic Summary by Intersection and Date";

run;

Output:

                                               Traffic Summary by Intersection and Date

Intersection_ID Date Vehicle_Count Average_Speed Accident_Occurred
INT001 01JAN2025 120 45 No Accident
    130 47 No Accident
INT002 01JAN2025 95 50 No Accident
    100 52 No Accident
INT003 01JAN2025 110 40 Accident
    115 42 No Accident

/*Generates a report summarizing traffic data by intersection and date.*/


6. PROC SGPLOT: Visualizing Data

proc sgplot data=urban_traffic_data;

    series x=Time y=Vehicle_Count / group=Intersection_ID;

    title "Vehicle Count Over Time by Intersection";

run;

/*Creates a line plot showing vehicle counts over time for each intersection.*/


7. PROC SQL: Advanced Data Queries

proc sql;

    create table high_traffic as

    select Intersection_ID, Date, sum(Vehicle_Count) as Total_Vehicles

    from urban_traffic_data

    group by Intersection_ID, Date

    having Total_Vehicles > 1000;

quit;

proc print;run;

Log:

NOTE: Table WORK.HIGH_TRAFFIC created, with 0 rows and 3 columns.

/*Identifies intersections with high traffic volumes on specific dates.*/


8. PROC UNIVARIATE: Detailed Statistical Analysis

proc univariate data=urban_traffic_data;

    var Average_Speed;

    histogram Average_Speed / normal;

    inset mean std / position=ne;

    title "Distribution of Average Speeds";

run;

Output:

                                                        Distribution of Average Speeds

                                                        The UNIVARIATE Procedure
                                              Fitted Normal Distribution for Average_Speed

Parameters for Normal Distribution
Parameter Symbol Estimate
Mean Mu 46
Std Dev Sigma 4.604346


Goodness-of-Fit Tests for Normal Distribution
Test Statistic p Value
Kolmogorov-Smirnov D 0.14083988 Pr > D >0.150
Cramer-von Mises W-Sq 0.02085136 Pr > W-Sq >0.250
Anderson-Darling A-Sq 0.15729075 Pr > A-Sq >0.250


Quantiles for Normal Distribution
Percent Quantile
Observed Estimated
1.0 40.0000 35.2887
5.0 40.0000 38.4265
10.0 40.0000 40.0993
25.0 42.0000 42.8944
50.0 46.0000 46.0000
75.0 50.0000 49.1056
90.0 52.0000 51.9007
95.0 52.0000 53.5735
99.0 52.0000 56.7113


/*Analyzes the distribution of average speeds, including a histogram and statistical measures.*/


9. PROC CORR: Correlation Analysis

proc corr data=urban_traffic_data;

    var Vehicle_Count Average_Speed;

    title "Correlation Between Vehicle Count and Average Speed";

run;

Output:

                                    Correlation Between Vehicle Count and Average Speed

                                                            The CORR Procedure

2 Variables: Vehicle_Count Average_Speed


Simple Statistics
Variable N Mean Std Dev Sum Minimum Maximum
Vehicle_Count 6 111.66667 12.90994 670.00000 95.00000 130.00000
Average_Speed 6 46.00000 4.60435 276.00000 40.00000 52.00000


Pearson Correlation Coefficients, N = 6
Prob > |r| under H0: Rho=0
  Vehicle_Count Average_Speed
Vehicle_Count
1.00000
 
-0.43740
0.3857
Average_Speed
-0.43740
0.3857
1.00000
 

/*Examines the relationship between vehicle count and average speed.*/


PRACTICE AND COMMENT YOUR CODE: 

-->PLEASE FOLLOW OUR BLOG FOR MORE UPDATES.

TO FOLLOW OUR TELEGRAM CHANNEL CLICK HERE

Comments