270.BRIDGE ANALYSIS USING PROC PRINT | PROC SQL | PROC FREQ | PROC MEANS | PROC REPORT | PROC TRANSPOSE | SAS MACROS FOR AUTOMATED BRIDGE DATA INSIGHTS
BRIDGE ANALYSIS USING PROC PRINT | PROC SQL | PROC FREQ | PROC MEANS | PROC REPORT | PROC TRANSPOSE | SAS MACROS FOR AUTOMATED BRIDGE DATA INSIGHTS
/*Creating a dataset of bridges in INDIA*/
1. Sample data input
options nocenter;
data bridges;
length BridgeName $25 Type $15 Location $20 Material $20;
input BridgeName $ Type $ Length Location $ YearBuilt Material $;
datalines;
HowrahBridge Cantilever 656 Kolkata 1943 Steel
VidyasagarSetu CableStayed 823 Kolkata 1992 Steel
ChenabBridge Arch 1315 Reasi 2022 Steel
BandraWorliSeaLink CableStayed 5600 Mumbai 2009 SteelConcrete
DobraChanti Suspension 725 NewTehri 2020 Steel
AtalSetu CableStayed 592 Basohli 2015 Concrete
NewYamunaBridge CableStayed 1510 Allahabad 2005 Concrete
SignatureBridge CableStayed 675 Delhi 2018 SteelConcrete
SyansuBridge Suspension 375 NewTehri 2007 Steel
;
run;
proc print data=bridges noobs;
title "Bridge Data in India";
run;
Output:
| BridgeName | Type | Location | Material | Length | YearBuilt |
|---|---|---|---|---|---|
| HowrahBridge | Cantilever | Kolkata | Steel | 656 | 1943 |
| VidyasagarSetu | CableStayed | Kolkata | Steel | 823 | 1992 |
| ChenabBridge | Arch | Reasi | Steel | 1315 | 2022 |
| BandraWorliSeaLink | CableStayed | Mumbai | SteelConcrete | 5600 | 2009 |
| DobraChanti | Suspension | NewTehri | Steel | 725 | 2020 |
| AtalSetu | CableStayed | Basohli | Concrete | 592 | 2015 |
| NewYamunaBridge | CableStayed | Allahabad | Concrete | 1510 | 2005 |
| SignatureBridge | CableStayed | Delhi | SteelConcrete | 675 | 2018 |
| SyansuBridge | Suspension | NewTehri | Steel | 375 | 2007 |
2. PROC SORT to sort bridges by Length in descending order
proc sort data=bridges out=bridges_sorted;
by descending Length;
run;
proc print;run;
Output:
| Obs | BridgeName | Type | Location | Material | Length | YearBuilt |
|---|---|---|---|---|---|---|
| 1 | BandraWorliSeaLink | CableStayed | Mumbai | SteelConcrete | 5600 | 2009 |
| 2 | NewYamunaBridge | CableStayed | Allahabad | Concrete | 1510 | 2005 |
| 3 | ChenabBridge | Arch | Reasi | Steel | 1315 | 2022 |
| 4 | VidyasagarSetu | CableStayed | Kolkata | Steel | 823 | 1992 |
| 5 | DobraChanti | Suspension | NewTehri | Steel | 725 | 2020 |
| 6 | SignatureBridge | CableStayed | Delhi | SteelConcrete | 675 | 2018 |
| 7 | HowrahBridge | Cantilever | Kolkata | Steel | 656 | 1943 |
| 8 | AtalSetu | CableStayed | Basohli | Concrete | 592 | 2015 |
| 9 | SyansuBridge | Suspension | NewTehri | Steel | 375 | 2007 |
3. PROC SQL to find top 5 longest bridges
proc sql outobs=5;
title "Top 5 Longest Bridges in India";
select BridgeName, Type, Length, Location, YearBuilt
from bridges_sorted;
quit;
Output:
| BridgeName | Type | Length | Location | YearBuilt |
|---|---|---|---|---|
| BandraWorliSeaLink | CableStayed | 5600 | Mumbai | 2009 |
| NewYamunaBridge | CableStayed | 1510 | Allahabad | 2005 |
| ChenabBridge | Arch | 1315 | Reasi | 2022 |
| VidyasagarSetu | CableStayed | 823 | Kolkata | 1992 |
| DobraChanti | Suspension | 725 | NewTehri | 2020 |
4. PROC FREQ to get frequency of bridge types
proc freq data=bridges;
tables Type / nocum noprint out=TypeFreq;
run;
proc print data=TypeFreq;
run;
Output:
| Obs | Type | COUNT | PERCENT |
|---|---|---|---|
| 1 | Arch | 1 | 11.1111 |
| 2 | CableStayed | 5 | 55.5556 |
| 3 | Cantilever | 1 | 11.1111 |
| 4 | Suspension | 2 | 22.2222 |
5. PROC MEANS to get stats of bridge lengths
proc means data=bridges mean median min max n;
var Length;
title "Descriptive Statistics for Bridge Lengths";
run;
Output:
The MEANS Procedure
| Analysis Variable : Length | ||||
|---|---|---|---|---|
| Mean | Median | Minimum | Maximum | N |
| 1363.44 | 725.0000000 | 375.0000000 | 5600.00 | 9 |
6. Macro to filter bridge data based on minimum length
%macro FilterBridge(min_len);
proc sql;
select BridgeName, Type, Length, Location
from bridges
where Length >= &min_len;
quit;
%mend FilterBridge;
%FilterBridge(700);
Output:
| BridgeName | Type | Length | Location |
|---|---|---|---|
| VidyasagarSetu | CableStayed | 823 | Kolkata |
| ChenabBridge | Arch | 1315 | Reasi |
| BandraWorliSeaLink | CableStayed | 5600 | Mumbai |
| DobraChanti | Suspension | 725 | NewTehri |
| NewYamunaBridge | CableStayed | 1510 | Allahabad |
7. Using PROC REPORT for a detailed report
proc report data=bridges nowd;
columns Type BridgeName Length Location YearBuilt;
define Type / group;
define BridgeName / display;
define Length / analysis mean;
define Location / display;
define YearBuilt / display;
title "Detailed Bridge Report Grouped by Type";
run;
Output:
| Type | BridgeName | Length | Location | YearBuilt |
|---|---|---|---|---|
| Arch | ChenabBridge | 1315 | Reasi | 2022 |
| CableStayed | VidyasagarSetu | 823 | Kolkata | 1992 |
| BandraWorliSeaLink | 5600 | Mumbai | 2009 | |
| AtalSetu | 592 | Basohli | 2015 | |
| NewYamunaBridge | 1510 | Allahabad | 2005 | |
| SignatureBridge | 675 | Delhi | 2018 | |
| Cantilever | HowrahBridge | 656 | Kolkata | 1943 |
| Suspension | DobraChanti | 725 | NewTehri | 2020 |
| SyansuBridge | 375 | NewTehri | 2007 |
8. Creating a macro for detailed bridge statistics by type
%macro BridgeStats(bridge_type);
proc means data=bridges n mean stddev min max maxdec=2;
where Type = "&bridge_type";
var Length YearBuilt;
title "Statistics for Bridge Type: &bridge_type";
run;
%mend BridgeStats;
%BridgeStats(CableStayed);
Output:
The MEANS Procedure
| Variable | N | Mean | Std Dev | Minimum | Maximum |
|---|---|---|---|---|---|
Length YearBuilt | 5 5 | 1840.00 2007.80 | 2132.81 10.18 | 592.00 1992.00 | 5600.00 2018.00 |
8. Macro to create frequency report with PROC REPORT
%macro BridgeFreqReport;
proc freq data=bridges order=freq;
tables Type / out=FreqOut;
run;
proc report data=FreqOut nowd;
columns Type count percent;
define Type / group;
define count / analysis sum;
define percent / analysis mean format=5.1;
title "Frequency Report of Bridge Types";
run;
%mend BridgeFreqReport;
%BridgeFreqReport;
Output:
The FREQ Procedure
| Type | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|
| CableStayed | 5 | 55.56 | 5 | 55.56 |
| Suspension | 2 | 22.22 | 7 | 77.78 |
| Arch | 1 | 11.11 | 8 | 88.89 |
| Cantilever | 1 | 11.11 | 9 | 100.00 |
| Type | Frequency Count | Percent of Total Frequency |
|---|---|---|
| Arch | 1 | 11.1 |
| CableStayed | 5 | 55.6 |
| Cantilever | 1 | 11.1 |
| Suspension | 2 | 22.2 |
9. Using PROC TRANSPOSE to pivot the frequency data
proc transpose data=FreqOut out=TypeFreqT(drop=_name_);
id Type;
var Count;
run;
proc print data=TypeFreqT noobs;
title "Transposed Frequency Table of Bridge Types";
run;
Output:
| _LABEL_ | CableStayed | Suspension | Arch | Cantilever |
|---|---|---|---|---|
| Frequency Count | 5 | 2 | 1 | 1 |
10. PROC SQL to calculate average length by material
proc sql;
select Material, avg(Length) as AvgLength format=8.2
from bridges
group by Material;
quit;
| Material | AvgLength |
|---|---|
| Concrete | 1051.00 |
| Steel | 778.80 |
| SteelConcrete | 3137.50 |
Comments
Post a Comment