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
- Dataset Design & Variables
- Creating Base Incident Dataset
- Date Handling using MDY, INTCK, INTNX
- Character & Numeric Functions Usage
- PROC SQL Analytics
- PROC FREQ – Root Cause Analysis
- PROC MEANS – Cost & Severity Summary
- PROC UNIVARIATE – Distribution Analysis
- PROC CORR – Relationship Analysis
- PROC SGPLOT – Visualization
- Macros for:
- Incident Severity Classification
- Fraud Detection Logic
- Date Derivations
- SET, MERGE, APPEND, TRANSPOSE
- 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:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 |
| 2 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 |
| 3 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 |
| 4 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 |
| 5 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 |
| 6 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 |
| 7 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 |
| 8 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 |
| 9 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 |
| 10 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 |
| 11 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 |
| 12 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 |
| 13 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 |
| 14 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 |
| 15 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 |
· 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:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score | Days_Since_Incident | Review_Date |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 | 755 | 23421 |
| 2 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 | 729 | 23445 |
| 3 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 | 705 | 23471 |
| 4 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 | 690 | 23486 |
| 5 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 | 677 | 23498 |
| 6 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 | 664 | 23511 |
| 7 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 | 639 | 23537 |
| 8 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 | 627 | 23549 |
| 9 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 | 617 | 23558 |
| 10 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 | 600 | 23575 |
| 11 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 | 583 | 23593 |
| 12 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 | 566 | 23610 |
| 13 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 | 549 | 23627 |
| 14 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 | 537 | 23639 |
| 15 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 | 524 | 23651 |
· 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:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score | Days_Since_Incident | Review_Date | Industry_Upper | Industry_Lower | Industry_Proper | Root_Cause_Clean | Incident_Label | Prevention_Percentage | Cost_Adjusted |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 | 755 | 23421 | MANUFACTURING | manufacturing | Manufacturing | Machine Failure | INC001-Manufacturing | 0.60 | 47250 |
| 2 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 | 729 | 23445 | CONSTRUCTION | construction | Construction | Fall Hazard | INC002-Construction | 0.40 | 157500 |
| 3 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 | 705 | 23471 | HEALTHCARE | healthcare | Healthcare | Needle Injury | INC003-Healthcare | 0.75 | 18900 |
| 4 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 | 690 | 23486 | IT SERVICES | it services | It Services | Ergonomic Issue | INC004-IT Services | 0.90 | 3150 |
| 5 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 | 677 | 23498 | LOGISTICS | logistics | Logistics | Vehicle Accident | INC005-Logistics | 0.55 | 54600 |
| 6 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 | 664 | 23511 | MANUFACTURING | manufacturing | Manufacturing | Chemical Exposure | INC006-Manufacturing | 0.65 | 23100 |
| 7 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 | 639 | 23537 | CONSTRUCTION | construction | Construction | Equipment Failure | INC007-Construction | 0.50 | 81900 |
| 8 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 | 627 | 23549 | HEALTHCARE | healthcare | Healthcare | Slip | INC008-Healthcare | 0.85 | 4200 |
| 9 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 | 617 | 23558 | LOGISTICS | logistics | Logistics | Fire Accident | INC009-Logistics | 0.30 | 220500 |
| 10 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 | 600 | 23575 | IT SERVICES | it services | It Services | Stress Injury | INC010-IT Services | 0.70 | 9450 |
| 11 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 | 583 | 23593 | MANUFACTURING | manufacturing | Manufacturing | Electrical Hazard | INC011-Manufacturing | 0.58 | 50400 |
| 12 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 | 566 | 23610 | CONSTRUCTION | construction | Construction | Tool Misuse | INC012-Construction | 0.68 | 26250 |
| 13 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 | 549 | 23627 | HEALTHCARE | healthcare | Healthcare | Patient Handling | INC013-Healthcare | 0.52 | 63000 |
| 14 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 | 537 | 23639 | LOGISTICS | logistics | Logistics | Manual Handling | INC014-Logistics | 0.88 | 7350 |
| 15 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 | 524 | 23651 | IT SERVICES | it services | It Services | Eye Strain | INC015-IT Services | 0.78 | 12600 |
· 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:
| Obs | Industry | Incident_Count | Total_Lost_Days | Avg_Compensation | Avg_Prevention |
|---|---|---|---|---|---|
| 1 | Construction | 3 | 77 | $84,333 | 52.6667 |
| 2 | Healthcare | 3 | 28 | $27,333 | 70.6667 |
| 3 | IT Services | 3 | 10 | $8,000 | 79.3333 |
| 4 | Logistics | 3 | 81 | $89,667 | 57.6667 |
| 5 | Manufacturing | 3 | 35 | $38,333 | 61.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_Cause | Frequency |
|---|---|
| Chemical Exposure | 1 |
| Electrical Hazard | 1 |
| Equipment Failure | 1 |
| Ergonomic Issue | 1 |
| Eye Strain | 1 |
| Fall Hazard | 1 |
| Fire Accident | 1 |
| Machine Failure | 1 |
| Manual Handling | 1 |
| Needle Injury | 1 |
| Patient Handling | 1 |
| Slip | 1 |
| Stress Injury | 1 |
| Tool Misuse | 1 |
| Vehicle Accident | 1 |
| Severity_Level | Frequency |
|---|---|
| Critical | 2 |
| High | 5 |
| Low | 3 |
| Medium | 5 |
· 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
| Variable | Mean | Minimum | Maximum | Sum |
|---|---|---|---|---|
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 | |||
|---|---|---|---|
| N | 15 | Sum Weights | 15 |
| Mean | 49533.3333 | Sum Observations | 743000 |
| Std Deviation | 58703.695 | Variance | 3446123810 |
| Skewness | 1.91950422 | Kurtosis | 3.48959698 |
| Uncorrected SS | 8.5049E10 | Corrected SS | 4.82457E10 |
| Coeff Variation | 118.513516 | Std Error Mean | 15157.2289 |
| Basic Statistical Measures | |||
|---|---|---|---|
| Location | Variability | ||
| Mean | 49533.33 | Std Deviation | 58704 |
| Median | 25000.00 | Variance | 3446123810 |
| Mode | . | Range | 207000 |
| Interquartile Range | 51000 | ||
| Tests for Location: Mu0=0 | ||||
|---|---|---|---|---|
| Test | Statistic | p Value | ||
| Student's t | t | 3.267968 | Pr > |t| | 0.0056 |
| Sign | M | 7.5 | Pr >= |M| | <.0001 |
| Signed Rank | S | 60 | Pr >= |S| | <.0001 |
| Quantiles (Definition 5) | |
|---|---|
| Level | Quantile |
| 100% Max | 210000 |
| 99% | 210000 |
| 95% | 210000 |
| 90% | 150000 |
| 75% Q3 | 60000 |
| 50% Median | 25000 |
| 25% Q1 | 9000 |
| 10% | 4000 |
| 5% | 3000 |
| 1% | 3000 |
| 0% Min | 3000 |
| Extreme Observations | |||
|---|---|---|---|
| Lowest | Highest | ||
| Value | Obs | Value | Obs |
| 3000 | 4 | 52000 | 5 |
| 4000 | 8 | 60000 | 13 |
| 7000 | 14 | 78000 | 7 |
| 9000 | 10 | 150000 | 2 |
| 12000 | 15 | 210000 | 9 |
The UNIVARIATE Procedure
· 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 | ||||||
|---|---|---|---|---|---|---|
| Variable | N | Mean | Std Dev | Sum | Minimum | Maximum |
| Lost_Work_Days | 15 | 15.40000 | 16.68960 | 231.00000 | 1.00000 | 60.00000 |
| Compensation_Cost | 15 | 49533 | 58704 | 743000 | 3000 | 210000 |
| Prevention_Score | 15 | 64.26667 | 17.45798 | 964.00000 | 30.00000 | 90.00000 |
| Pearson Correlation Coefficients, N = 15 Prob > |r| under H0: Rho=0 | |||
|---|---|---|---|
| Lost_Work_Days | Compensation_Cost | Prevention_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:
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:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score | Days_Since_Incident | Review_Date | Industry_Upper | Industry_Lower | Industry_Proper | Root_Cause_Clean | Incident_Label | Prevention_Percentage | Cost_Adjusted | Risk_Level |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 | 755 | 23421 | MANUFACTURING | manufacturing | Manufacturing | Machine Failure | INC001-Manufacturing | 0.60 | 47250 | High |
| 2 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 | 729 | 23445 | CONSTRUCTION | construction | Construction | Fall Hazard | INC002-Construction | 0.40 | 157500 | Extreme |
| 3 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 | 705 | 23471 | HEALTHCARE | healthcare | Healthcare | Needle Injury | INC003-Healthcare | 0.75 | 18900 | Moderate |
| 4 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 | 690 | 23486 | IT SERVICES | it services | It Services | Ergonomic Issue | INC004-IT Services | 0.90 | 3150 | Low |
| 5 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 | 677 | 23498 | LOGISTICS | logistics | Logistics | Vehicle Accident | INC005-Logistics | 0.55 | 54600 | High |
| 6 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 | 664 | 23511 | MANUFACTURING | manufacturing | Manufacturing | Chemical Exposure | INC006-Manufacturing | 0.65 | 23100 | Moderate |
| 7 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 | 639 | 23537 | CONSTRUCTION | construction | Construction | Equipment Failure | INC007-Construction | 0.50 | 81900 | High |
| 8 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 | 627 | 23549 | HEALTHCARE | healthcare | Healthcare | Slip | INC008-Healthcare | 0.85 | 4200 | Low |
| 9 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 | 617 | 23558 | LOGISTICS | logistics | Logistics | Fire Accident | INC009-Logistics | 0.30 | 220500 | Extreme |
| 10 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 | 600 | 23575 | IT SERVICES | it services | It Services | Stress Injury | INC010-IT Services | 0.70 | 9450 | Moderate |
| 11 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 | 583 | 23593 | MANUFACTURING | manufacturing | Manufacturing | Electrical Hazard | INC011-Manufacturing | 0.58 | 50400 | High |
| 12 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 | 566 | 23610 | CONSTRUCTION | construction | Construction | Tool Misuse | INC012-Construction | 0.68 | 26250 | Moderate |
| 13 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 | 549 | 23627 | HEALTHCARE | healthcare | Healthcare | Patient Handling | INC013-Healthcare | 0.52 | 63000 | High |
| 14 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 | 537 | 23639 | LOGISTICS | logistics | Logistics | Manual Handling | INC014-Logistics | 0.88 | 7350 | Low |
| 15 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 | 524 | 23651 | IT SERVICES | it services | It Services | Eye Strain | INC015-IT Services | 0.78 | 12600 | Moderate |
· 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:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score | Days_Since_Incident | Review_Date | Industry_Upper | Industry_Lower | Industry_Proper | Root_Cause_Clean | Incident_Label | Prevention_Percentage | Cost_Adjusted | Risk_Level | Fraud_Flag |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 | 755 | 23421 | MANUFACTURING | manufacturing | Manufacturing | Machine Failure | INC001-Manufacturing | 0.60 | 47250 | High | NO |
| 2 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 | 729 | 23445 | CONSTRUCTION | construction | Construction | Fall Hazard | INC002-Construction | 0.40 | 157500 | Extreme | NO |
| 3 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 | 705 | 23471 | HEALTHCARE | healthcare | Healthcare | Needle Injury | INC003-Healthcare | 0.75 | 18900 | Moderate | NO |
| 4 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 | 690 | 23486 | IT SERVICES | it services | It Services | Ergonomic Issue | INC004-IT Services | 0.90 | 3150 | Low | NO |
| 5 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 | 677 | 23498 | LOGISTICS | logistics | Logistics | Vehicle Accident | INC005-Logistics | 0.55 | 54600 | High | NO |
| 6 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 | 664 | 23511 | MANUFACTURING | manufacturing | Manufacturing | Chemical Exposure | INC006-Manufacturing | 0.65 | 23100 | Moderate | NO |
| 7 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 | 639 | 23537 | CONSTRUCTION | construction | Construction | Equipment Failure | INC007-Construction | 0.50 | 81900 | High | NO |
| 8 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 | 627 | 23549 | HEALTHCARE | healthcare | Healthcare | Slip | INC008-Healthcare | 0.85 | 4200 | Low | NO |
| 9 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 | 617 | 23558 | LOGISTICS | logistics | Logistics | Fire Accident | INC009-Logistics | 0.30 | 220500 | Extreme | YES |
| 10 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 | 600 | 23575 | IT SERVICES | it services | It Services | Stress Injury | INC010-IT Services | 0.70 | 9450 | Moderate | NO |
| 11 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 | 583 | 23593 | MANUFACTURING | manufacturing | Manufacturing | Electrical Hazard | INC011-Manufacturing | 0.58 | 50400 | High | NO |
| 12 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 | 566 | 23610 | CONSTRUCTION | construction | Construction | Tool Misuse | INC012-Construction | 0.68 | 26250 | Moderate | NO |
| 13 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 | 549 | 23627 | HEALTHCARE | healthcare | Healthcare | Patient Handling | INC013-Healthcare | 0.52 | 63000 | High | NO |
| 14 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 | 537 | 23639 | LOGISTICS | logistics | Logistics | Manual Handling | INC014-Logistics | 0.88 | 7350 | Low | NO |
| 15 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 | 524 | 23651 | IT SERVICES | it services | It Services | Eye Strain | INC015-IT Services | 0.78 | 12600 | Moderate | NO |
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_ | Construction | Healthcare | IT Services | Logistics | Manufacturing |
|---|---|---|---|---|---|---|
| 1 | Incident_Count | 3 | 3 | 3 | 3 | 3 |
proc sort data=safety_classified;by Industry;run;
proc print data=safety_classified;
run;
OUTPUT:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score | Days_Since_Incident | Review_Date | Industry_Upper | Industry_Lower | Industry_Proper | Root_Cause_Clean | Incident_Label | Prevention_Percentage | Cost_Adjusted | Risk_Level |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 | 729 | 23445 | CONSTRUCTION | construction | Construction | Fall Hazard | INC002-Construction | 0.40 | 157500 | Extreme |
| 2 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 | 639 | 23537 | CONSTRUCTION | construction | Construction | Equipment Failure | INC007-Construction | 0.50 | 81900 | High |
| 3 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 | 566 | 23610 | CONSTRUCTION | construction | Construction | Tool Misuse | INC012-Construction | 0.68 | 26250 | Moderate |
| 4 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 | 705 | 23471 | HEALTHCARE | healthcare | Healthcare | Needle Injury | INC003-Healthcare | 0.75 | 18900 | Moderate |
| 5 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 | 627 | 23549 | HEALTHCARE | healthcare | Healthcare | Slip | INC008-Healthcare | 0.85 | 4200 | Low |
| 6 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 | 549 | 23627 | HEALTHCARE | healthcare | Healthcare | Patient Handling | INC013-Healthcare | 0.52 | 63000 | High |
| 7 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 | 690 | 23486 | IT SERVICES | it services | It Services | Ergonomic Issue | INC004-IT Services | 0.90 | 3150 | Low |
| 8 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 | 600 | 23575 | IT SERVICES | it services | It Services | Stress Injury | INC010-IT Services | 0.70 | 9450 | Moderate |
| 9 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 | 524 | 23651 | IT SERVICES | it services | It Services | Eye Strain | INC015-IT Services | 0.78 | 12600 | Moderate |
| 10 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 | 677 | 23498 | LOGISTICS | logistics | Logistics | Vehicle Accident | INC005-Logistics | 0.55 | 54600 | High |
| 11 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 | 617 | 23558 | LOGISTICS | logistics | Logistics | Fire Accident | INC009-Logistics | 0.30 | 220500 | Extreme |
| 12 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 | 537 | 23639 | LOGISTICS | logistics | Logistics | Manual Handling | INC014-Logistics | 0.88 | 7350 | Low |
| 13 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 | 755 | 23421 | MANUFACTURING | manufacturing | Manufacturing | Machine Failure | INC001-Manufacturing | 0.60 | 47250 | High |
| 14 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 | 664 | 23511 | MANUFACTURING | manufacturing | Manufacturing | Chemical Exposure | INC006-Manufacturing | 0.65 | 23100 | Moderate |
| 15 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 | 583 | 23593 | MANUFACTURING | manufacturing | Manufacturing | Electrical Hazard | INC011-Manufacturing | 0.58 | 50400 | High |
proc sort data=industry_summary;by Industry;run;
proc print data=industry_summary;
run;
OUTPUT:
| Obs | Industry | Incident_Count | Total_Lost_Days | Avg_Compensation | Avg_Prevention |
|---|---|---|---|---|---|
| 1 | Construction | 3 | 77 | $84,333 | 52.6667 |
| 2 | Healthcare | 3 | 28 | $27,333 | 70.6667 |
| 3 | IT Services | 3 | 10 | $8,000 | 79.3333 |
| 4 | Logistics | 3 | 81 | $89,667 | 57.6667 |
| 5 | Manufacturing | 3 | 35 | $38,333 | 61.0000 |
data combined;
merge safety_classified
industry_summary;
by Industry;
run;
proc print data=combined;
run;
OUTPUT:
| Obs | Incident_ID | Industry | Severity_Level | Root_Cause | Reported_By | Region | Incident_Date | Lost_Work_Days | Compensation_Cost | Prevention_Score | Days_Since_Incident | Review_Date | Industry_Upper | Industry_Lower | Industry_Proper | Root_Cause_Clean | Incident_Label | Prevention_Percentage | Cost_Adjusted | Risk_Level | Incident_Count | Total_Lost_Days | Avg_Compensation | Avg_Prevention |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | INC002 | Construction | Critical | Fall Hazard | Supervisor | West | 10FEB2024 | 45 | 150000 | 40 | 729 | 23445 | CONSTRUCTION | construction | Construction | Fall Hazard | INC002-Construction | 0.40 | 157500 | Extreme | 3 | 77 | $84,333 | 52.6667 |
| 2 | INC007 | Construction | High | Equipment Failure | Supervisor | North | 10MAY2024 | 22 | 78000 | 50 | 639 | 23537 | CONSTRUCTION | construction | Construction | Equipment Failure | INC007-Construction | 0.50 | 81900 | High | 3 | 77 | $84,333 | 52.6667 |
| 3 | INC012 | Construction | Medium | Tool Misuse | Worker | South | 22JUL2024 | 10 | 25000 | 68 | 566 | 23610 | CONSTRUCTION | construction | Construction | Tool Misuse | INC012-Construction | 0.68 | 26250 | Moderate | 3 | 77 | $84,333 | 52.6667 |
| 4 | INC003 | Healthcare | Medium | Needle Injury | Worker | North | 05MAR2024 | 6 | 18000 | 75 | 705 | 23471 | HEALTHCARE | healthcare | Healthcare | Needle Injury | INC003-Healthcare | 0.75 | 18900 | Moderate | 3 | 28 | $27,333 | 70.6667 |
| 5 | INC008 | Healthcare | Low | Slip | Worker | East | 22MAY2024 | 2 | 4000 | 85 | 627 | 23549 | HEALTHCARE | healthcare | Healthcare | Slip | INC008-Healthcare | 0.85 | 4200 | Low | 3 | 28 | $27,333 | 70.6667 |
| 6 | INC013 | Healthcare | High | Patient Handling | Supervisor | North | 08AUG2024 | 20 | 60000 | 52 | 549 | 23627 | HEALTHCARE | healthcare | Healthcare | Patient Handling | INC013-Healthcare | 0.52 | 63000 | High | 3 | 28 | $27,333 | 70.6667 |
| 7 | INC004 | IT Services | Low | Ergonomic Issue | Worker | East | 20MAR2024 | 1 | 3000 | 90 | 690 | 23486 | IT SERVICES | it services | It Services | Ergonomic Issue | INC004-IT Services | 0.90 | 3150 | Low | 3 | 10 | $8,000 | 79.3333 |
| 8 | INC010 | IT Services | Medium | Stress Injury | Worker | South | 18JUN2024 | 4 | 9000 | 70 | 600 | 23575 | IT SERVICES | it services | It Services | Stress Injury | INC010-IT Services | 0.70 | 9450 | Moderate | 3 | 10 | $8,000 | 79.3333 |
| 9 | INC015 | IT Services | Medium | Eye Strain | Worker | West | 02SEP2024 | 5 | 12000 | 78 | 524 | 23651 | IT SERVICES | it services | It Services | Eye Strain | INC015-IT Services | 0.78 | 12600 | Moderate | 3 | 10 | $8,000 | 79.3333 |
| 10 | INC005 | Logistics | High | Vehicle Accident | Supervisor | South | 02APR2024 | 18 | 52000 | 55 | 677 | 23498 | LOGISTICS | logistics | Logistics | Vehicle Accident | INC005-Logistics | 0.55 | 54600 | High | 3 | 81 | $89,667 | 57.6667 |
| 11 | INC009 | Logistics | Critical | Fire Accident | Supervisor | West | 01JUN2024 | 60 | 210000 | 30 | 617 | 23558 | LOGISTICS | logistics | Logistics | Fire Accident | INC009-Logistics | 0.30 | 220500 | Extreme | 3 | 81 | $89,667 | 57.6667 |
| 12 | INC014 | Logistics | Low | Manual Handling | Worker | East | 20AUG2024 | 3 | 7000 | 88 | 537 | 23639 | LOGISTICS | logistics | Logistics | Manual Handling | INC014-Logistics | 0.88 | 7350 | Low | 3 | 81 | $89,667 | 57.6667 |
| 13 | INC001 | Manufacturing | High | Machine Failure | Supervisor | South | 15JAN2024 | 12 | 45000 | 60 | 755 | 23421 | MANUFACTURING | manufacturing | Manufacturing | Machine Failure | INC001-Manufacturing | 0.60 | 47250 | High | 3 | 35 | $38,333 | 61.0000 |
| 14 | INC006 | Manufacturing | Medium | Chemical Exposure | Worker | West | 15APR2024 | 8 | 22000 | 65 | 664 | 23511 | MANUFACTURING | manufacturing | Manufacturing | Chemical Exposure | INC006-Manufacturing | 0.65 | 23100 | Moderate | 3 | 35 | $38,333 | 61.0000 |
| 15 | INC011 | Manufacturing | High | Electrical Hazard | Supervisor | East | 05JUL2024 | 15 | 48000 | 58 | 583 | 23593 | MANUFACTURING | manufacturing | Manufacturing | Electrical Hazard | INC011-Manufacturing | 0.58 | 50400 | High | 3 | 35 | $38,333 | 61.0000 |
14. PROC DATASETS DELETE
proc datasets library=work nolist;
delete industry_t;
quit;
LOG:
· 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
Comments
Post a Comment