395.Can smart SAS macros help identify high-risk safety incidents before they become disasters?

Can smart SAS macros help identify high-risk safety incidents before they become disasters?

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

HERE IN THIS PROJECT WE USED THESE SAS STATEMENTS —
DATA STEP | PROC SQL |  PROC PRINT | PROC SGPLOT | MACROS | PROC CORR | PROC MEANS | PROC FREQ | PROC UNIVARIATE | APPEND | PROC SORT | MERGE | PROC TRANSPOSE | PROC DATASETS DELETE | DATA FUNCTIONS

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

INTRODUCTION

Workplace safety is one of the most critical areas for organizations across manufacturing, construction, healthcare, logistics, IT services, and energy sectors. Every safety incident not only affects employee health but also results in:

  • Productivity loss
  • Legal liabilities
  • Insurance claims
  • Increased compensation costs
  • Damage to company reputation

Modern organizations use data analytics to monitor, analyze, and prevent safety incidents before they escalate.

BUSINESS CONTEXT

Imagine a multinational company with operations across multiple industries:

  • Manufacturing
  • Construction
  • Healthcare
  • IT Services
  • Logistics

The Safety & Compliance Department wants answers to questions like:

  • Which industries have the highest severity incidents?
  • Are compensation costs aligned with severity?
  • Are there suspicious (fraud-like) claims?
  • Which root causes are most frequent?
  • How effective are prevention measures?
  • Can we classify incidents by risk level automatically?


TABLE OF CONTENTS

  1. Dataset Design & Variables
  2. Creating Base Incident Dataset
  3. Date Handling using MDY, INTCK, INTNX
  4. Character & Numeric Functions Usage
  5. PROC SQL Analytics
  6. PROC FREQ – Root Cause Analysis
  7. PROC MEANS – Cost & Severity Summary
  8. PROC UNIVARIATE – Distribution Analysis
  9. PROC CORR – Relationship Analysis
  10. PROC SGPLOT – Visualization
  11. Macros for:
    • Incident Severity Classification
    • Fraud Detection Logic
    • Date Derivations
  12. SET, MERGE, APPEND, TRANSPOSE
  13. PROC DATASETS DELETE

1. DATASET DESIGN

Variables Used

Variable

Description

Incident_ID

Unique incident identifier

Industry

Industry type

Incident_Date

Date of incident

Severity_Level

Low / Medium / High / Critical

Lost_Work_Days

Number of days lost

Compensation_Cost

Claim amount

Root_Cause

Cause of incident

Prevention_Score

Score (0–100)

Prevention_Percentage

Converted %

Reported_By

Supervisor / Worker

Region

Operational region

2. CREATING BASE DATASET

data safety_incidents;

    length Incident_ID $6 Industry $20 Severity_Level $10 

           Root_Cause $30 Reported_By $15 Region $15;

    format Incident_Date date9.;


    Incident_ID='INC001'; Industry='Manufacturing'; Incident_Date=mdy(1,15,2024);

    Severity_Level='High'; Lost_Work_Days=12; Compensation_Cost=45000;

    Root_Cause='Machine Failure'; Prevention_Score=60; Reported_By='Supervisor'; 

    Region='South'; 

    output;


    Incident_ID='INC002'; Industry='Construction'; Incident_Date=mdy(2,10,2024);

    Severity_Level='Critical'; Lost_Work_Days=45; Compensation_Cost=150000;

    Root_Cause='Fall Hazard'; Prevention_Score=40; Reported_By='Supervisor'; 

    Region='West'; 

    output;


    Incident_ID='INC003'; Industry='Healthcare'; Incident_Date=mdy(3,5,2024);

    Severity_Level='Medium'; Lost_Work_Days=6; Compensation_Cost=18000;

    Root_Cause='Needle Injury'; Prevention_Score=75; Reported_By='Worker'; 

    Region='North'; 

    output;


    Incident_ID='INC004'; Industry='IT Services'; Incident_Date=mdy(3,20,2024);

    Severity_Level='Low'; Lost_Work_Days=1; Compensation_Cost=3000;

    Root_Cause='Ergonomic Issue'; Prevention_Score=90; Reported_By='Worker';

    Region='East'; 

    output;


    Incident_ID='INC005'; Industry='Logistics'; Incident_Date=mdy(4,2,2024);

    Severity_Level='High'; Lost_Work_Days=18; Compensation_Cost=52000;

    Root_Cause='Vehicle Accident'; Prevention_Score=55; Reported_By='Supervisor';

    Region='South'; 

    output;


    Incident_ID='INC006'; Industry='Manufacturing'; Incident_Date=mdy(4,15,2024);

    Severity_Level='Medium'; Lost_Work_Days=8; Compensation_Cost=22000;

    Root_Cause='Chemical Exposure'; Prevention_Score=65; Reported_By='Worker';

    Region='West';

    output;


    Incident_ID='INC007'; Industry='Construction'; Incident_Date=mdy(5,10,2024);

    Severity_Level='High'; Lost_Work_Days=22; Compensation_Cost=78000;

    Root_Cause='Equipment Failure'; Prevention_Score=50; Reported_By='Supervisor';

    Region='North'; 

    output;


    Incident_ID='INC008'; Industry='Healthcare'; Incident_Date=mdy(5,22,2024);

    Severity_Level='Low'; Lost_Work_Days=2; Compensation_Cost=4000;

    Root_Cause='Slip'; Prevention_Score=85; Reported_By='Worker'; Region='East';

    output;


    Incident_ID='INC009'; Industry='Logistics'; Incident_Date=mdy(6,1,2024);

    Severity_Level='Critical'; Lost_Work_Days=60; Compensation_Cost=210000;

    Root_Cause='Fire Accident'; Prevention_Score=30; Reported_By='Supervisor'; 

    Region='West'; 

    output;


    Incident_ID='INC010'; Industry='IT Services'; Incident_Date=mdy(6,18,2024);

    Severity_Level='Medium'; Lost_Work_Days=4; Compensation_Cost=9000;

    Root_Cause='Stress Injury'; Prevention_Score=70; Reported_By='Worker'; 

    Region='South'; 

    output;


    Incident_ID='INC011'; Industry='Manufacturing'; Incident_Date=mdy(7,5,2024);

    Severity_Level='High'; Lost_Work_Days=15; Compensation_Cost=48000;

    Root_Cause='Electrical Hazard'; Prevention_Score=58; Reported_By='Supervisor'; 

    Region='East';

    output;


    Incident_ID='INC012'; Industry='Construction'; Incident_Date=mdy(7,22,2024);

    Severity_Level='Medium'; Lost_Work_Days=10; Compensation_Cost=25000;

    Root_Cause='Tool Misuse'; Prevention_Score=68; Reported_By='Worker';

    Region='South'; 

    output;


    Incident_ID='INC013'; Industry='Healthcare'; Incident_Date=mdy(8,8,2024);

    Severity_Level='High'; Lost_Work_Days=20; Compensation_Cost=60000;

    Root_Cause='Patient Handling'; Prevention_Score=52; Reported_By='Supervisor'; 

    Region='North';

    output;


    Incident_ID='INC014'; Industry='Logistics'; Incident_Date=mdy(8,20,2024);

    Severity_Level='Low'; Lost_Work_Days=3; Compensation_Cost=7000;

    Root_Cause='Manual Handling'; Prevention_Score=88; Reported_By='Worker';

    Region='East';

    output;


    Incident_ID='INC015'; Industry='IT Services'; Incident_Date=mdy(9,2,2024);

    Severity_Level='Medium'; Lost_Work_Days=5; Compensation_Cost=12000;

    Root_Cause='Eye Strain'; Prevention_Score=78; Reported_By='Worker'; 

    Region='West'; 

    output;

run;

proc print data=safety_incidents;

run;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_Score
1INC001ManufacturingHighMachine FailureSupervisorSouth15JAN2024124500060
2INC002ConstructionCriticalFall HazardSupervisorWest10FEB20244515000040
3INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR202461800075
4INC004IT ServicesLowErgonomic IssueWorkerEast20MAR20241300090
5INC005LogisticsHighVehicle AccidentSupervisorSouth02APR2024185200055
6INC006ManufacturingMediumChemical ExposureWorkerWest15APR202482200065
7INC007ConstructionHighEquipment FailureSupervisorNorth10MAY2024227800050
8INC008HealthcareLowSlipWorkerEast22MAY20242400085
9INC009LogisticsCriticalFire AccidentSupervisorWest01JUN20246021000030
10INC010IT ServicesMediumStress InjuryWorkerSouth18JUN20244900070
11INC011ManufacturingHighElectrical HazardSupervisorEast05JUL2024154800058
12INC012ConstructionMediumTool MisuseWorkerSouth22JUL2024102500068
13INC013HealthcareHighPatient HandlingSupervisorNorth08AUG2024206000052
14INC014LogisticsLowManual HandlingWorkerEast20AUG20243700088
15INC015IT ServicesMediumEye StrainWorkerWest02SEP202451200078

·  Used to manually create mock data

·  Common in POCs, interviews, demos

·  length ensures proper character storage

·  mdy() ensures correct SAS date values

3. DATE CALCULATIONS USING INTCK & INTNX

data safety_dates;

    set safety_incidents;

    Days_Since_Incident = intck('day', Incident_Date, today());

    Review_Date = intnx('month', Incident_Date, 1, 'same');

run;

proc print data=safety_dates;

run;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_ScoreDays_Since_IncidentReview_Date
1INC001ManufacturingHighMachine FailureSupervisorSouth15JAN202412450006075523421
2INC002ConstructionCriticalFall HazardSupervisorWest10FEB2024451500004072923445
3INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR20246180007570523471
4INC004IT ServicesLowErgonomic IssueWorkerEast20MAR2024130009069023486
5INC005LogisticsHighVehicle AccidentSupervisorSouth02APR202418520005567723498
6INC006ManufacturingMediumChemical ExposureWorkerWest15APR20248220006566423511
7INC007ConstructionHighEquipment FailureSupervisorNorth10MAY202422780005063923537
8INC008HealthcareLowSlipWorkerEast22MAY2024240008562723549
9INC009LogisticsCriticalFire AccidentSupervisorWest01JUN2024602100003061723558
10INC010IT ServicesMediumStress InjuryWorkerSouth18JUN2024490007060023575
11INC011ManufacturingHighElectrical HazardSupervisorEast05JUL202415480005858323593
12INC012ConstructionMediumTool MisuseWorkerSouth22JUL202410250006856623610
13INC013HealthcareHighPatient HandlingSupervisorNorth08AUG202420600005254923627
14INC014LogisticsLowManual HandlingWorkerEast20AUG2024370008853723639
15INC015IT ServicesMediumEye StrainWorkerWest02SEP20245120007852423651

·  INTCK → time difference (used in SLA checks)

·  INTNX → future review scheduling

·  Very common in compliance analytics

4. CHARACTER & NUMERIC FUNCTIONS

data safety_clean;

    set safety_dates;

    Industry_Upper = upcase(Industry);

    Industry_Lower = lowcase(Industry);

    Industry_Proper = propcase(Industry);

    Root_Cause_Clean = strip(trim(Root_Cause));

    Incident_Label = catx('-', Incident_ID, Industry);

    Prevention_Percentage = Prevention_Score / 100;

    Cost_Adjusted = round(Compensation_Cost * 1.05, 1);

run;

proc print data=safety_clean;

run;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_ScoreDays_Since_IncidentReview_DateIndustry_UpperIndustry_LowerIndustry_ProperRoot_Cause_CleanIncident_LabelPrevention_PercentageCost_Adjusted
1INC001ManufacturingHighMachine FailureSupervisorSouth15JAN202412450006075523421MANUFACTURINGmanufacturingManufacturingMachine FailureINC001-Manufacturing0.6047250
2INC002ConstructionCriticalFall HazardSupervisorWest10FEB2024451500004072923445CONSTRUCTIONconstructionConstructionFall HazardINC002-Construction0.40157500
3INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR20246180007570523471HEALTHCAREhealthcareHealthcareNeedle InjuryINC003-Healthcare0.7518900
4INC004IT ServicesLowErgonomic IssueWorkerEast20MAR2024130009069023486IT SERVICESit servicesIt ServicesErgonomic IssueINC004-IT Services0.903150
5INC005LogisticsHighVehicle AccidentSupervisorSouth02APR202418520005567723498LOGISTICSlogisticsLogisticsVehicle AccidentINC005-Logistics0.5554600
6INC006ManufacturingMediumChemical ExposureWorkerWest15APR20248220006566423511MANUFACTURINGmanufacturingManufacturingChemical ExposureINC006-Manufacturing0.6523100
7INC007ConstructionHighEquipment FailureSupervisorNorth10MAY202422780005063923537CONSTRUCTIONconstructionConstructionEquipment FailureINC007-Construction0.5081900
8INC008HealthcareLowSlipWorkerEast22MAY2024240008562723549HEALTHCAREhealthcareHealthcareSlipINC008-Healthcare0.854200
9INC009LogisticsCriticalFire AccidentSupervisorWest01JUN2024602100003061723558LOGISTICSlogisticsLogisticsFire AccidentINC009-Logistics0.30220500
10INC010IT ServicesMediumStress InjuryWorkerSouth18JUN2024490007060023575IT SERVICESit servicesIt ServicesStress InjuryINC010-IT Services0.709450
11INC011ManufacturingHighElectrical HazardSupervisorEast05JUL202415480005858323593MANUFACTURINGmanufacturingManufacturingElectrical HazardINC011-Manufacturing0.5850400
12INC012ConstructionMediumTool MisuseWorkerSouth22JUL202410250006856623610CONSTRUCTIONconstructionConstructionTool MisuseINC012-Construction0.6826250
13INC013HealthcareHighPatient HandlingSupervisorNorth08AUG202420600005254923627HEALTHCAREhealthcareHealthcarePatient HandlingINC013-Healthcare0.5263000
14INC014LogisticsLowManual HandlingWorkerEast20AUG2024370008853723639LOGISTICSlogisticsLogisticsManual HandlingINC014-Logistics0.887350
15INC015IT ServicesMediumEye StrainWorkerWest02SEP20245120007852423651IT SERVICESit servicesIt ServicesEye StrainINC015-IT Services0.7812600

·  strip/trim → remove messy spaces

·  cat/catx → labeling

·  upcase/lowcase/propcase → reporting consistency

·  Numeric functions → cost projections

5. PROC SQL – INDUSTRY LEVEL SUMMARY

proc sql;

    create table industry_summary as

    select Industry,

           count(*) as Incident_Count,

           sum(Lost_Work_Days) as Total_Lost_Days,

           mean(Compensation_Cost) as Avg_Compensation format=dollar12.,

           mean(Prevention_Score) as Avg_Prevention

    from safety_clean

    group by Industry;

quit;

proc print data=industry_summary;

run;

OUTPUT:

ObsIndustryIncident_CountTotal_Lost_DaysAvg_CompensationAvg_Prevention
1Construction377$84,33352.6667
2Healthcare328$27,33370.6667
3IT Services310$8,00079.3333
4Logistics381$89,66757.6667
5Manufacturing335$38,33361.0000

·  Preferred in corporate analytics

·  Easy joins, grouping, aggregations

·  Similar to real databases

6. PROC FREQ – ROOT CAUSE ANALYSIS

proc freq data=safety_clean;

    tables Root_Cause Severity_Level / nocum nopercent;

run;

OUTPUT:

The FREQ Procedure

Root_CauseFrequency
Chemical Exposure1
Electrical Hazard1
Equipment Failure1
Ergonomic Issue1
Eye Strain1
Fall Hazard1
Fire Accident1
Machine Failure1
Manual Handling1
Needle Injury1
Patient Handling1
Slip1
Stress Injury1
Tool Misuse1
Vehicle Accident1
Severity_LevelFrequency
Critical2
High5
Low3
Medium5

·  Identifies most common accident causes

·  Helps management prioritize safety training

7. PROC MEANS

proc means data=safety_clean mean min max sum;

    var Lost_Work_Days Compensation_Cost Prevention_Score;

run;

OUTPUT:

The MEANS Procedure

VariableMeanMinimumMaximumSum
Lost_Work_Days
Compensation_Cost
Prevention_Score
15.4000000
49533.33
64.2666667
1.0000000
3000.00
30.0000000
60.0000000
210000.00
90.0000000
231.0000000
743000.00
964.0000000

·  Fast statistical summary

·  Used in almost every SAS job

8. PROC UNIVARIATE

proc univariate data=safety_clean;

    var Compensation_Cost;

    histogram Compensation_Cost;

run;

OUTPUT:

The UNIVARIATE Procedure

Variable: Compensation_Cost

Moments
N15Sum Weights15
Mean49533.3333Sum Observations743000
Std Deviation58703.695Variance3446123810
Skewness1.91950422Kurtosis3.48959698
Uncorrected SS8.5049E10Corrected SS4.82457E10
Coeff Variation118.513516Std Error Mean15157.2289
Basic Statistical Measures
LocationVariability
Mean49533.33Std Deviation58704
Median25000.00Variance3446123810
Mode.Range207000
  Interquartile Range51000
Tests for Location: Mu0=0
TestStatisticp Value
Student's tt3.267968Pr > |t|0.0056
SignM7.5Pr >= |M|<.0001
Signed RankS60Pr >= |S|<.0001
Quantiles (Definition 5)
LevelQuantile
100% Max210000
99%210000
95%210000
90%150000
75% Q360000
50% Median25000
25% Q19000
10%4000
5%3000
1%3000
0% Min3000
Extreme Observations
LowestHighest
ValueObsValueObs
30004520005
400086000013
700014780007
9000101500002
12000152100009

The UNIVARIATE Procedure

Histogram for Compensation_Cost

·  Detects skewness

·  Identifies extreme claim amounts

9. PROC CORR

proc corr data=safety_clean;

    var Lost_Work_Days Compensation_Cost Prevention_Score;

run;

OUTPUT:

The CORR Procedure

3 Variables:Lost_Work_Days Compensation_Cost Prevention_Score
Simple Statistics
VariableNMeanStd DevSumMinimumMaximum
Lost_Work_Days1515.4000016.68960231.000001.0000060.00000
Compensation_Cost1549533587047430003000210000
Prevention_Score1564.2666717.45798964.0000030.0000090.00000
Pearson Correlation Coefficients, N = 15
Prob > |r| under H0: Rho=0
 Lost_Work_DaysCompensation_CostPrevention_Score
Lost_Work_Days
1.00000
 
0.99748
<.0001
-0.90254
<.0001
Compensation_Cost
0.99748
<.0001
1.00000
 
-0.89310
<.0001
Prevention_Score
-0.90254
<.0001
-0.89310
<.0001
1.00000
 

·  High correlation between lost days & compensation

·  Negative correlation with prevention score

10. PROC SGPLOT

proc sgplot data=safety_clean;

    vbar Industry / response=Compensation_Cost stat=mean;

    title "Average Compensation Cost by Industry";

run;

OUTPUT:

The SGPlot Procedure


11. MACRO – INCIDENT SEVERITY CLASSIFICATION

%macro classify_severity;

data safety_classified;

    set safety_clean;

    length Risk_Level $10;

    if Severity_Level='Critical' or Compensation_Cost > 100000 then Risk_Level='Extreme';

    else if Severity_Level='High' then Risk_Level='High';

    else if Severity_Level='Medium' then Risk_Level='Moderate';

    else Risk_Level='Low';

run;

proc print data=safety_classified;

run;

%mend;


%classify_severity;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_ScoreDays_Since_IncidentReview_DateIndustry_UpperIndustry_LowerIndustry_ProperRoot_Cause_CleanIncident_LabelPrevention_PercentageCost_AdjustedRisk_Level
1INC001ManufacturingHighMachine FailureSupervisorSouth15JAN202412450006075523421MANUFACTURINGmanufacturingManufacturingMachine FailureINC001-Manufacturing0.6047250High
2INC002ConstructionCriticalFall HazardSupervisorWest10FEB2024451500004072923445CONSTRUCTIONconstructionConstructionFall HazardINC002-Construction0.40157500Extreme
3INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR20246180007570523471HEALTHCAREhealthcareHealthcareNeedle InjuryINC003-Healthcare0.7518900Moderate
4INC004IT ServicesLowErgonomic IssueWorkerEast20MAR2024130009069023486IT SERVICESit servicesIt ServicesErgonomic IssueINC004-IT Services0.903150Low
5INC005LogisticsHighVehicle AccidentSupervisorSouth02APR202418520005567723498LOGISTICSlogisticsLogisticsVehicle AccidentINC005-Logistics0.5554600High
6INC006ManufacturingMediumChemical ExposureWorkerWest15APR20248220006566423511MANUFACTURINGmanufacturingManufacturingChemical ExposureINC006-Manufacturing0.6523100Moderate
7INC007ConstructionHighEquipment FailureSupervisorNorth10MAY202422780005063923537CONSTRUCTIONconstructionConstructionEquipment FailureINC007-Construction0.5081900High
8INC008HealthcareLowSlipWorkerEast22MAY2024240008562723549HEALTHCAREhealthcareHealthcareSlipINC008-Healthcare0.854200Low
9INC009LogisticsCriticalFire AccidentSupervisorWest01JUN2024602100003061723558LOGISTICSlogisticsLogisticsFire AccidentINC009-Logistics0.30220500Extreme
10INC010IT ServicesMediumStress InjuryWorkerSouth18JUN2024490007060023575IT SERVICESit servicesIt ServicesStress InjuryINC010-IT Services0.709450Moderate
11INC011ManufacturingHighElectrical HazardSupervisorEast05JUL202415480005858323593MANUFACTURINGmanufacturingManufacturingElectrical HazardINC011-Manufacturing0.5850400High
12INC012ConstructionMediumTool MisuseWorkerSouth22JUL202410250006856623610CONSTRUCTIONconstructionConstructionTool MisuseINC012-Construction0.6826250Moderate
13INC013HealthcareHighPatient HandlingSupervisorNorth08AUG202420600005254923627HEALTHCAREhealthcareHealthcarePatient HandlingINC013-Healthcare0.5263000High
14INC014LogisticsLowManual HandlingWorkerEast20AUG2024370008853723639LOGISTICSlogisticsLogisticsManual HandlingINC014-Logistics0.887350Low
15INC015IT ServicesMediumEye StrainWorkerWest02SEP20245120007852423651IT SERVICESit servicesIt ServicesEye StrainINC015-IT Services0.7812600Moderate

·  Automation

·  Reusability

·  Interview favorite topic

12. FRAUD DETECTION LOGIC 

%macro fraud_check;

data fraud_flags;

    set safety_classified;

length Fraud_Flag $5.;

    Fraud_Flag='NO';

    if Lost_Work_Days > 40 and Compensation_Cost > 150000 then Fraud_Flag='YES';

run;

proc print data=fraud_flags;

run;

%mend;


%fraud_check;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_ScoreDays_Since_IncidentReview_DateIndustry_UpperIndustry_LowerIndustry_ProperRoot_Cause_CleanIncident_LabelPrevention_PercentageCost_AdjustedRisk_LevelFraud_Flag
1INC001ManufacturingHighMachine FailureSupervisorSouth15JAN202412450006075523421MANUFACTURINGmanufacturingManufacturingMachine FailureINC001-Manufacturing0.6047250HighNO
2INC002ConstructionCriticalFall HazardSupervisorWest10FEB2024451500004072923445CONSTRUCTIONconstructionConstructionFall HazardINC002-Construction0.40157500ExtremeNO
3INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR20246180007570523471HEALTHCAREhealthcareHealthcareNeedle InjuryINC003-Healthcare0.7518900ModerateNO
4INC004IT ServicesLowErgonomic IssueWorkerEast20MAR2024130009069023486IT SERVICESit servicesIt ServicesErgonomic IssueINC004-IT Services0.903150LowNO
5INC005LogisticsHighVehicle AccidentSupervisorSouth02APR202418520005567723498LOGISTICSlogisticsLogisticsVehicle AccidentINC005-Logistics0.5554600HighNO
6INC006ManufacturingMediumChemical ExposureWorkerWest15APR20248220006566423511MANUFACTURINGmanufacturingManufacturingChemical ExposureINC006-Manufacturing0.6523100ModerateNO
7INC007ConstructionHighEquipment FailureSupervisorNorth10MAY202422780005063923537CONSTRUCTIONconstructionConstructionEquipment FailureINC007-Construction0.5081900HighNO
8INC008HealthcareLowSlipWorkerEast22MAY2024240008562723549HEALTHCAREhealthcareHealthcareSlipINC008-Healthcare0.854200LowNO
9INC009LogisticsCriticalFire AccidentSupervisorWest01JUN2024602100003061723558LOGISTICSlogisticsLogisticsFire AccidentINC009-Logistics0.30220500ExtremeYES
10INC010IT ServicesMediumStress InjuryWorkerSouth18JUN2024490007060023575IT SERVICESit servicesIt ServicesStress InjuryINC010-IT Services0.709450ModerateNO
11INC011ManufacturingHighElectrical HazardSupervisorEast05JUL202415480005858323593MANUFACTURINGmanufacturingManufacturingElectrical HazardINC011-Manufacturing0.5850400HighNO
12INC012ConstructionMediumTool MisuseWorkerSouth22JUL202410250006856623610CONSTRUCTIONconstructionConstructionTool MisuseINC012-Construction0.6826250ModerateNO
13INC013HealthcareHighPatient HandlingSupervisorNorth08AUG202420600005254923627HEALTHCAREhealthcareHealthcarePatient HandlingINC013-Healthcare0.5263000HighNO
14INC014LogisticsLowManual HandlingWorkerEast20AUG2024370008853723639LOGISTICSlogisticsLogisticsManual HandlingINC014-Logistics0.887350LowNO
15INC015IT ServicesMediumEye StrainWorkerWest02SEP20245120007852423651IT SERVICESit servicesIt ServicesEye StrainINC015-IT Services0.7812600ModerateNO

13. TRANSPOSE, APPEND, SORT,MERGE

proc transpose data=industry_summary out=industry_t;

    id Industry;

    var Incident_Count;

run;

proc print data=industry_t;

run;

OUTPUT:

Obs_NAME_ConstructionHealthcareIT ServicesLogisticsManufacturing
1Incident_Count33333

proc sort data=safety_classified;by Industry;run;

proc print data=safety_classified;

run;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_ScoreDays_Since_IncidentReview_DateIndustry_UpperIndustry_LowerIndustry_ProperRoot_Cause_CleanIncident_LabelPrevention_PercentageCost_AdjustedRisk_Level
1INC002ConstructionCriticalFall HazardSupervisorWest10FEB2024451500004072923445CONSTRUCTIONconstructionConstructionFall HazardINC002-Construction0.40157500Extreme
2INC007ConstructionHighEquipment FailureSupervisorNorth10MAY202422780005063923537CONSTRUCTIONconstructionConstructionEquipment FailureINC007-Construction0.5081900High
3INC012ConstructionMediumTool MisuseWorkerSouth22JUL202410250006856623610CONSTRUCTIONconstructionConstructionTool MisuseINC012-Construction0.6826250Moderate
4INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR20246180007570523471HEALTHCAREhealthcareHealthcareNeedle InjuryINC003-Healthcare0.7518900Moderate
5INC008HealthcareLowSlipWorkerEast22MAY2024240008562723549HEALTHCAREhealthcareHealthcareSlipINC008-Healthcare0.854200Low
6INC013HealthcareHighPatient HandlingSupervisorNorth08AUG202420600005254923627HEALTHCAREhealthcareHealthcarePatient HandlingINC013-Healthcare0.5263000High
7INC004IT ServicesLowErgonomic IssueWorkerEast20MAR2024130009069023486IT SERVICESit servicesIt ServicesErgonomic IssueINC004-IT Services0.903150Low
8INC010IT ServicesMediumStress InjuryWorkerSouth18JUN2024490007060023575IT SERVICESit servicesIt ServicesStress InjuryINC010-IT Services0.709450Moderate
9INC015IT ServicesMediumEye StrainWorkerWest02SEP20245120007852423651IT SERVICESit servicesIt ServicesEye StrainINC015-IT Services0.7812600Moderate
10INC005LogisticsHighVehicle AccidentSupervisorSouth02APR202418520005567723498LOGISTICSlogisticsLogisticsVehicle AccidentINC005-Logistics0.5554600High
11INC009LogisticsCriticalFire AccidentSupervisorWest01JUN2024602100003061723558LOGISTICSlogisticsLogisticsFire AccidentINC009-Logistics0.30220500Extreme
12INC014LogisticsLowManual HandlingWorkerEast20AUG2024370008853723639LOGISTICSlogisticsLogisticsManual HandlingINC014-Logistics0.887350Low
13INC001ManufacturingHighMachine FailureSupervisorSouth15JAN202412450006075523421MANUFACTURINGmanufacturingManufacturingMachine FailureINC001-Manufacturing0.6047250High
14INC006ManufacturingMediumChemical ExposureWorkerWest15APR20248220006566423511MANUFACTURINGmanufacturingManufacturingChemical ExposureINC006-Manufacturing0.6523100Moderate
15INC011ManufacturingHighElectrical HazardSupervisorEast05JUL202415480005858323593MANUFACTURINGmanufacturingManufacturingElectrical HazardINC011-Manufacturing0.5850400High

proc sort data=industry_summary;by Industry;run;

proc print data=industry_summary;

run;

OUTPUT:

ObsIndustryIncident_CountTotal_Lost_DaysAvg_CompensationAvg_Prevention
1Construction377$84,33352.6667
2Healthcare328$27,33370.6667
3IT Services310$8,00079.3333
4Logistics381$89,66757.6667
5Manufacturing335$38,33361.0000

data combined;

    merge safety_classified 

          industry_summary;

    by Industry;

run;

proc print data=combined;

run;

OUTPUT:

ObsIncident_IDIndustrySeverity_LevelRoot_CauseReported_ByRegionIncident_DateLost_Work_DaysCompensation_CostPrevention_ScoreDays_Since_IncidentReview_DateIndustry_UpperIndustry_LowerIndustry_ProperRoot_Cause_CleanIncident_LabelPrevention_PercentageCost_AdjustedRisk_LevelIncident_CountTotal_Lost_DaysAvg_CompensationAvg_Prevention
1INC002ConstructionCriticalFall HazardSupervisorWest10FEB2024451500004072923445CONSTRUCTIONconstructionConstructionFall HazardINC002-Construction0.40157500Extreme377$84,33352.6667
2INC007ConstructionHighEquipment FailureSupervisorNorth10MAY202422780005063923537CONSTRUCTIONconstructionConstructionEquipment FailureINC007-Construction0.5081900High377$84,33352.6667
3INC012ConstructionMediumTool MisuseWorkerSouth22JUL202410250006856623610CONSTRUCTIONconstructionConstructionTool MisuseINC012-Construction0.6826250Moderate377$84,33352.6667
4INC003HealthcareMediumNeedle InjuryWorkerNorth05MAR20246180007570523471HEALTHCAREhealthcareHealthcareNeedle InjuryINC003-Healthcare0.7518900Moderate328$27,33370.6667
5INC008HealthcareLowSlipWorkerEast22MAY2024240008562723549HEALTHCAREhealthcareHealthcareSlipINC008-Healthcare0.854200Low328$27,33370.6667
6INC013HealthcareHighPatient HandlingSupervisorNorth08AUG202420600005254923627HEALTHCAREhealthcareHealthcarePatient HandlingINC013-Healthcare0.5263000High328$27,33370.6667
7INC004IT ServicesLowErgonomic IssueWorkerEast20MAR2024130009069023486IT SERVICESit servicesIt ServicesErgonomic IssueINC004-IT Services0.903150Low310$8,00079.3333
8INC010IT ServicesMediumStress InjuryWorkerSouth18JUN2024490007060023575IT SERVICESit servicesIt ServicesStress InjuryINC010-IT Services0.709450Moderate310$8,00079.3333
9INC015IT ServicesMediumEye StrainWorkerWest02SEP20245120007852423651IT SERVICESit servicesIt ServicesEye StrainINC015-IT Services0.7812600Moderate310$8,00079.3333
10INC005LogisticsHighVehicle AccidentSupervisorSouth02APR202418520005567723498LOGISTICSlogisticsLogisticsVehicle AccidentINC005-Logistics0.5554600High381$89,66757.6667
11INC009LogisticsCriticalFire AccidentSupervisorWest01JUN2024602100003061723558LOGISTICSlogisticsLogisticsFire AccidentINC009-Logistics0.30220500Extreme381$89,66757.6667
12INC014LogisticsLowManual HandlingWorkerEast20AUG2024370008853723639LOGISTICSlogisticsLogisticsManual HandlingINC014-Logistics0.887350Low381$89,66757.6667
13INC001ManufacturingHighMachine FailureSupervisorSouth15JAN202412450006075523421MANUFACTURINGmanufacturingManufacturingMachine FailureINC001-Manufacturing0.6047250High335$38,33361.0000
14INC006ManufacturingMediumChemical ExposureWorkerWest15APR20248220006566423511MANUFACTURINGmanufacturingManufacturingChemical ExposureINC006-Manufacturing0.6523100Moderate335$38,33361.0000
15INC011ManufacturingHighElectrical HazardSupervisorEast05JUL202415480005858323593MANUFACTURINGmanufacturingManufacturingElectrical HazardINC011-Manufacturing0.5850400High335$38,33361.0000

14. PROC DATASETS DELETE

proc datasets library=work nolist;

    delete industry_t;

quit;

LOG:

NOTE: Deleting WORK.INDUSTRY_T (memtype=DATA).

·  Memory cleanup

·  Production best practice

Conclusion

This Workplace Safety Incidents Analytics project shows how raw safety data can be transformed into meaningful business insights using SAS. By applying PROC SQL, statistical procedures, macros, and date logic, we identified high-risk incidents, analyzed compensation impact, monitored SLA compliance, and detected potential fraud patterns.

The project demonstrates real-world problem solving, where data is not just analyzed but used to prevent future incidents, reduce costs, and improve employee safety. Overall, it reflects how SAS supports decision-making, compliance, and risk management in modern organizations.


INTERVIEW QUESTIONS FOR YOU

·  What is a correlated subquery?

·  How do you use CASE WHEN in SAS SQL?

·  What is the difference between UNION and UNION ALL?


About the Author:

SAS Learning Hub is a data analytics and SAS programming platform focused on clinical, financial, and real-world data analysis. The content is created by professionals with academic training in Pharmaceutics and hands-on experience in Base SAS, PROC SQL, Macros, SDTM, and ADaM, providing practical and industry-relevant SAS learning resources.


Disclaimer:

The datasets and analysis in this article are created for educational and demonstration purposes only. They do not represent SAFETY INCIDENTS data.


Our Mission:

This blog provides industry-focused SAS programming tutorials and analytics projects covering finance, healthcare, and technology.


This project is suitable for:

·  Students learning SAS

·  Data analysts building portfolios

·  Professionals preparing for SAS interviews

·  Bloggers writing about analytics 


Follow Us On : 


 


--->Follow our blog for more SAS-based analytics projects and industry data models.

To deepen your understanding of SAS analytics, please refer to our other data science and industry-focused projects listed below:





About Us | Contact Privacy Policy

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