384.Is your factory really performing well, or just showing good numbers on paper?Using Sas Can we Get it
Is your factory really performing well, or just showing good numbers on paper?Using Sas Can we Get it
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 DATASETS DELETE
INTRODUCTION
In modern
manufacturing industries, factory production lines are the backbone of
operational efficiency. Every production line consumes energy, produces goods,
generates defects, and experiences downtime. Monitoring these variables
continuously is critical for:
- Operational efficiency
- Cost control
- Quality assurance
- Fraud or data manipulation
detection
- Predictive maintenance
This
project simulates a real-world industrial analytics scenario where a data
analyst or SAS programmer is asked to:
- Create production data
- Perform descriptive and
statistical analysis
- Detect abnormal or
fraudulent patterns
- Classify utilization
- Visualize performance
- Provide business insights
CONTENTS
- Dataset Creation
- Date Handling using MDY /
INTCK / INTNX
- Character & Numeric
Transformations
- Utilization Classification
Macro
- Fraud Detection Macro
- Statistical Analysis
- Correlation Analysis
- Visualization
- Transpose & Reshaping
- Merging & Appending
- PROC DATASETS Cleanup
- Final Business Insights
STEP 1 — DATASET CREATION
data factory_lines;
input Line_ID $ Product_Type $ Units_Produced Defect_Rate
Downtime_Hours Energy_Consumption Efficiency_Score Production_Date :date9.;
format Production_Date date9.;
datalines;
L01 electronics 1200 2.5 1.2 450 88 01JAN2024
L02 furniture 950 3.8 2.4 520 82 03JAN2024
L03 electronics 1500 1.2 0.5 610 92 05JAN2024
L04 automotive 1800 4.9 3.8 900 75 06JAN2024
L05 textile 700 5.5 4.2 300 70 08JAN2024
L06 electronics 1600 1.5 0.7 650 93 10JAN2024
L07 furniture 1100 2.9 1.5 480 85 11JAN2024
L08 automotive 1900 6.1 5.0 950 68 13JAN2024
L09 textile 800 4.2 3.0 350 74 14JAN2024
L10 electronics 1400 2.0 1.0 590 90 16JAN2024
L11 furniture 1000 3.5 2.0 500 83 18JAN2024
L12 automotive 2000 7.5 6.0 1000 65 20JAN2024
L13 textile 750 4.8 3.6 330 72 21JAN2024
L14 electronics 1700 1.1 0.4 680 95 23JAN2024
L15 automotive 2100 8.2 7.0 1100 60 25JAN2024
;
run;
proc print data=factory_lines;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date |
|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 |
| 2 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 |
| 3 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 |
| 4 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 |
| 5 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 |
| 6 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 |
| 7 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 |
| 8 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 |
| 9 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 |
| 10 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 |
| 11 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 |
| 12 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 |
| 13 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 |
| 14 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 |
| 15 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 |
Simulates MES (Manufacturing Execution System) feed.
Represents line-wise production KPIs.
Used in interviews to show:
·
Domain understanding
·
Realistic variable naming
·
Correct data types
STEP 2 — DATE LOGIC (MDY, INTCK, INTNX)
data factory_dates;
set factory_lines;
Report_Date = mdy(2,1,2024);
Days_From_Report = intck('day', Production_Date, Report_Date);
Next_Service_Date = intnx('month', Production_Date, 1);
run;
proc print data=factory_dates;
var Line_ID Product_Type Production_Date Report_Date Days_From_Report Next_Service_Date;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Production_Date | Report_Date | Days_From_Report | Next_Service_Date |
|---|---|---|---|---|---|---|
| 1 | L01 | electron | 01JAN2024 | 23407 | 31 | 23407 |
| 2 | L02 | furnitur | 03JAN2024 | 23407 | 29 | 23407 |
| 3 | L03 | electron | 05JAN2024 | 23407 | 27 | 23407 |
| 4 | L04 | automoti | 06JAN2024 | 23407 | 26 | 23407 |
| 5 | L05 | textile | 08JAN2024 | 23407 | 24 | 23407 |
| 6 | L06 | electron | 10JAN2024 | 23407 | 22 | 23407 |
| 7 | L07 | furnitur | 11JAN2024 | 23407 | 21 | 23407 |
| 8 | L08 | automoti | 13JAN2024 | 23407 | 19 | 23407 |
| 9 | L09 | textile | 14JAN2024 | 23407 | 18 | 23407 |
| 10 | L10 | electron | 16JAN2024 | 23407 | 16 | 23407 |
| 11 | L11 | furnitur | 18JAN2024 | 23407 | 14 | 23407 |
| 12 | L12 | automoti | 20JAN2024 | 23407 | 12 | 23407 |
| 13 | L13 | textile | 21JAN2024 | 23407 | 11 | 23407 |
| 14 | L14 | electron | 23JAN2024 | 23407 | 9 | 23407 |
| 15 | L15 | automoti | 25JAN2024 | 23407 | 7 | 23407 |
|
Function |
Purpose |
|
MDY |
Creates
reference reporting date |
|
INTCK |
Measures
operational lag |
|
INTNX |
Schedules
next maintenance |
Used in:
- SLA tracking
- Preventive maintenance
systems
STEP 3 — CHARACTER & NUMERIC FUNCTIONS
data factory_clean;
set factory_dates;
Product_Type_Upper = upcase(Product_Type);
Product_Type_Proper = propcase(Product_Type);
Product_Key = catx('_', Line_ID, Product_Type);
Defect_Adjusted = coalesce(Defect_Rate,0);
run;
proc print data=factory_clean;
var Line_ID Product_Type Product_Type_Upper Product_Type_Proper Product_Key Defect_Rate Defect_Adjusted;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Product_Type_Upper | Product_Type_Proper | Product_Key | Defect_Rate | Defect_Adjusted |
|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | ELECTRON | Electron | L01_electron | 2.5 | 2.5 |
| 2 | L02 | furnitur | FURNITUR | Furnitur | L02_furnitur | 3.8 | 3.8 |
| 3 | L03 | electron | ELECTRON | Electron | L03_electron | 1.2 | 1.2 |
| 4 | L04 | automoti | AUTOMOTI | Automoti | L04_automoti | 4.9 | 4.9 |
| 5 | L05 | textile | TEXTILE | Textile | L05_textile | 5.5 | 5.5 |
| 6 | L06 | electron | ELECTRON | Electron | L06_electron | 1.5 | 1.5 |
| 7 | L07 | furnitur | FURNITUR | Furnitur | L07_furnitur | 2.9 | 2.9 |
| 8 | L08 | automoti | AUTOMOTI | Automoti | L08_automoti | 6.1 | 6.1 |
| 9 | L09 | textile | TEXTILE | Textile | L09_textile | 4.2 | 4.2 |
| 10 | L10 | electron | ELECTRON | Electron | L10_electron | 2.0 | 2.0 |
| 11 | L11 | furnitur | FURNITUR | Furnitur | L11_furnitur | 3.5 | 3.5 |
| 12 | L12 | automoti | AUTOMOTI | Automoti | L12_automoti | 7.5 | 7.5 |
| 13 | L13 | textile | TEXTILE | Textile | L13_textile | 4.8 | 4.8 |
| 14 | L14 | electron | ELECTRON | Electron | L14_electron | 1.1 | 1.1 |
| 15 | L15 | automoti | AUTOMOTI | Automoti | L15_automoti | 8.2 | 8.2 |
|
Function |
Business
Use |
|
UPCASE |
Standardization |
|
PROPCASE |
Reporting |
|
CATX |
Unique
keys |
|
COALESCE |
Missing
handling |
STEP 4 — UTILIZATION CLASSIFICATION MACRO
%macro utilization;
data factory_util;
set factory_clean;
if Efficiency_Score >= 90 then Utilization="Excellent";
else if Efficiency_Score >= 80 then Utilization="Good";
else if Efficiency_Score >= 70 then Utilization="Average";
else Utilization="Poor";
run;
proc print data=factory_util;
run;
%mend;
%utilization;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date | Report_Date | Days_From_Report | Next_Service_Date | Product_Type_Upper | Product_Type_Proper | Product_Key | Defect_Adjusted | Utilization |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | 23407 | 31 | 23407 | ELECTRON | Electron | L01_electron | 2.5 | Good |
| 2 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | 23407 | 29 | 23407 | FURNITUR | Furnitur | L02_furnitur | 3.8 | Good |
| 3 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | 23407 | 27 | 23407 | ELECTRON | Electron | L03_electron | 1.2 | Excellent |
| 4 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | 23407 | 26 | 23407 | AUTOMOTI | Automoti | L04_automoti | 4.9 | Average |
| 5 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | 23407 | 24 | 23407 | TEXTILE | Textile | L05_textile | 5.5 | Average |
| 6 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | 23407 | 22 | 23407 | ELECTRON | Electron | L06_electron | 1.5 | Excellent |
| 7 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | 23407 | 21 | 23407 | FURNITUR | Furnitur | L07_furnitur | 2.9 | Good |
| 8 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | 23407 | 19 | 23407 | AUTOMOTI | Automoti | L08_automoti | 6.1 | Poor |
| 9 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | 23407 | 18 | 23407 | TEXTILE | Textile | L09_textile | 4.2 | Average |
| 10 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | 23407 | 16 | 23407 | ELECTRON | Electron | L10_electron | 2.0 | Excellent |
| 11 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | 23407 | 14 | 23407 | FURNITUR | Furnitur | L11_furnitur | 3.5 | Good |
| 12 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | 23407 | 12 | 23407 | AUTOMOTI | Automoti | L12_automoti | 7.5 | Poor |
| 13 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | 23407 | 11 | 23407 | TEXTILE | Textile | L13_textile | 4.8 | Average |
| 14 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | 23407 | 9 | 23407 | ELECTRON | Electron | L14_electron | 1.1 | Excellent |
| 15 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | 23407 | 7 | 23407 | AUTOMOTI | Automoti | L15_automoti | 8.2 | Poor |
Automates:
·
Plant dashboards
·
KPI categorization
·
Performance banding
Shows:
·
Reusability
·
Enterprise coding style
STEP 5 — FRAUD DETECTION MACRO
%macro fraud;
data factory_fraud;
set factory_util;
if Defect_Rate > 7 and Downtime_Hours > 5 then Fraud_Flag="YES";
else Fraud_Flag="NO";
run;
proc print data=factory_fraud;
run;
%mend;
%fraud;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date | Report_Date | Days_From_Report | Next_Service_Date | Product_Type_Upper | Product_Type_Proper | Product_Key | Defect_Adjusted | Utilization | Fraud_Flag |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | 23407 | 31 | 23407 | ELECTRON | Electron | L01_electron | 2.5 | Good | NO |
| 2 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | 23407 | 29 | 23407 | FURNITUR | Furnitur | L02_furnitur | 3.8 | Good | NO |
| 3 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | 23407 | 27 | 23407 | ELECTRON | Electron | L03_electron | 1.2 | Excellent | NO |
| 4 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | 23407 | 26 | 23407 | AUTOMOTI | Automoti | L04_automoti | 4.9 | Average | NO |
| 5 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | 23407 | 24 | 23407 | TEXTILE | Textile | L05_textile | 5.5 | Average | NO |
| 6 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | 23407 | 22 | 23407 | ELECTRON | Electron | L06_electron | 1.5 | Excellent | NO |
| 7 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | 23407 | 21 | 23407 | FURNITUR | Furnitur | L07_furnitur | 2.9 | Good | NO |
| 8 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | 23407 | 19 | 23407 | AUTOMOTI | Automoti | L08_automoti | 6.1 | Poor | NO |
| 9 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | 23407 | 18 | 23407 | TEXTILE | Textile | L09_textile | 4.2 | Average | NO |
| 10 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | 23407 | 16 | 23407 | ELECTRON | Electron | L10_electron | 2.0 | Excellent | NO |
| 11 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | 23407 | 14 | 23407 | FURNITUR | Furnitur | L11_furnitur | 3.5 | Good | NO |
| 12 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | 23407 | 12 | 23407 | AUTOMOTI | Automoti | L12_automoti | 7.5 | Poor | YES |
| 13 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | 23407 | 11 | 23407 | TEXTILE | Textile | L13_textile | 4.8 | Average | NO |
| 14 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | 23407 | 9 | 23407 | ELECTRON | Electron | L14_electron | 1.1 | Excellent | NO |
| 15 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | 23407 | 7 | 23407 | AUTOMOTI | Automoti | L15_automoti | 8.2 | Poor | YES |
Detects:
·
Artificially inflated production
·
Manipulated defect logs
·
Fake efficiency metrics
Real-world use:
·
Internal audits
·
Compliance checks
·
Six Sigma reviews
STEP 6 — PROC SQL ANALYSIS
proc sql;
select Product_Type,
avg(Units_Produced) as Avg_Units,
avg(Defect_Rate) as Avg_Defect,
avg(Efficiency_Score) as Avg_Efficiency
from factory_fraud
group by Product_Type;
quit;
OUTPUT:
| Product_Type | Avg_Units | Avg_Defect | Avg_Efficiency |
|---|---|---|---|
| automoti | 1950 | 6.675 | 67 |
| electron | 1480 | 1.66 | 91.6 |
| furnitur | 1016.667 | 3.4 | 83.33333 |
| textile | 750 | 4.833333 | 72 |
Provides:
·
Management summary tables
·
Cross-product comparisons
Used for:
·
Board presentations
·
Manufacturing scorecards
STEP 7 — PROC FREQ
proc freq data=factory_fraud;
tables Product_Type*Utilization Fraud_Flag;
run;
OUTPUT:
The FREQ Procedure
|
| ||||||||||||||||||||||||||||||||||||||||||||||||
| Fraud_Flag | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|
| NO | 13 | 86.67 | 13 | 86.67 |
| YES | 2 | 13.33 | 15 | 100.00 |
Shows:
·
Utilization distribution
·
Fraud frequency
Used in:
·
Risk reports
·
Control dashboards
STEP 8 — PROC MEANS & UNIVARIATE
proc means data=factory_fraud mean min max;
var Units_Produced Defect_Rate Downtime_Hours Energy_Consumption Efficiency_Score;
run;
OUTPUT:
The MEANS Procedure
| Variable | Mean | Minimum | Maximum |
|---|---|---|---|
Units_Produced Defect_Rate Downtime_Hours Energy_Consumption Efficiency_Score | 1366.67 3.9800000 2.8200000 627.3333333 79.4666667 | 700.0000000 1.1000000 0.4000000 300.0000000 60.0000000 | 2100.00 8.2000000 7.0000000 1100.00 95.0000000 |
proc univariate data=factory_fraud;
var Efficiency_Score;
histogram;
run;
OUTPUT:
The UNIVARIATE Procedure
Variable: Efficiency_Score
| Moments | |||
|---|---|---|---|
| N | 15 | Sum Weights | 15 |
| Mean | 79.4666667 | Sum Observations | 1192 |
| Std Deviation | 11.1154119 | Variance | 123.552381 |
| Skewness | -0.1928899 | Kurtosis | -1.2330588 |
| Uncorrected SS | 96454 | Corrected SS | 1729.73333 |
| Coeff Variation | 13.9875149 | Std Error Mean | 2.869987 |
| Basic Statistical Measures | |||
|---|---|---|---|
| Location | Variability | ||
| Mean | 79.46667 | Std Deviation | 11.11541 |
| Median | 82.00000 | Variance | 123.55238 |
| Mode | . | Range | 35.00000 |
| Interquartile Range | 20.00000 | ||
| Tests for Location: Mu0=0 | ||||
|---|---|---|---|---|
| Test | Statistic | p Value | ||
| Student's t | t | 27.68886 | Pr > |t| | <.0001 |
| Sign | M | 7.5 | Pr >= |M| | <.0001 |
| Signed Rank | S | 60 | Pr >= |S| | <.0001 |
| Quantiles (Definition 5) | |
|---|---|
| Level | Quantile |
| 100% Max | 95 |
| 99% | 95 |
| 95% | 95 |
| 90% | 93 |
| 75% Q3 | 90 |
| 50% Median | 82 |
| 25% Q1 | 70 |
| 10% | 65 |
| 5% | 60 |
| 1% | 60 |
| 0% Min | 60 |
| Extreme Observations | |||
|---|---|---|---|
| Lowest | Highest | ||
| Value | Obs | Value | Obs |
| 60 | 15 | 88 | 1 |
| 65 | 12 | 90 | 10 |
| 68 | 8 | 92 | 3 |
| 70 | 5 | 93 | 6 |
| 72 | 13 | 95 | 14 |
The UNIVARIATE Procedure
Measures:
·
Central tendency
·
Outliers
·
Process stability
Used in:
·
SPC (Statistical Process Control)
·
Quality engineering
STEP 9 — CORRELATION
proc corr data=factory_fraud;
var Units_Produced Defect_Rate Downtime_Hours Energy_Consumption Efficiency_Score;
run;
OUTPUT:
The CORR Procedure
| 5 Variables: | Units_Produced Defect_Rate Downtime_Hours Energy_Consumption Efficiency_Score |
|---|
| Simple Statistics | ||||||
|---|---|---|---|---|---|---|
| Variable | N | Mean | Std Dev | Sum | Minimum | Maximum |
| Units_Produced | 15 | 1367 | 474.21615 | 20500 | 700.00000 | 2100 |
| Defect_Rate | 15 | 3.98000 | 2.20849 | 59.70000 | 1.10000 | 8.20000 |
| Downtime_Hours | 15 | 2.82000 | 2.07199 | 42.30000 | 0.40000 | 7.00000 |
| Energy_Consumption | 15 | 627.33333 | 253.41853 | 9410 | 300.00000 | 1100 |
| Efficiency_Score | 15 | 79.46667 | 11.11541 | 1192 | 60.00000 | 95.00000 |
| Pearson Correlation Coefficients, N = 15 Prob > |r| under H0: Rho=0 | |||||
|---|---|---|---|---|---|
| Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | |
| Units_Produced | 1.00000 | 0.27417 0.3227 | 0.33367 0.2242 | 0.95763 <.0001 | -0.16758 0.5505 |
| Defect_Rate | 0.27417 0.3227 | 1.00000 | 0.99442 <.0001 | 0.49202 0.0625 | -0.98337 <.0001 |
| Downtime_Hours | 0.33367 0.2242 | 0.99442 <.0001 | 1.00000 | 0.53894 0.0382 | -0.98079 <.0001 |
| Energy_Consumption | 0.95763 <.0001 | 0.49202 0.0625 | 0.53894 0.0382 | 1.00000 | -0.38572 0.1556 |
| Efficiency_Score | -0.16758 0.5505 | -0.98337 <.0001 | -0.98079 <.0001 | -0.38572 0.1556 | 1.00000 |
Reveals:
·
Energy vs Efficiency
·
Downtime vs Defects
Used for:
·
Root cause analysis
·
Lean manufacturing
STEP 10 — VISUALIZATION
proc sgplot data=factory_fraud;
scatter x=Energy_Consumption y=Efficiency_Score;
run;
OUTPUT:
Visual diagnostics:
·
Operational efficiency curve
·
Energy waste patterns
STEP 11 — TRANSPOSE
proc transpose data=factory_fraud out=factory_wide;
id Line_ID;
var Efficiency_Score;
run;
proc print data=factory_wide;
run;
OUTPUT:
| Obs | _NAME_ | L01 | L02 | L03 | L04 | L05 | L06 | L07 | L08 | L09 | L10 | L11 | L12 | L13 | L14 | L15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Efficiency_Score | 88 | 82 | 92 | 75 | 70 | 93 | 85 | 68 | 74 | 90 | 83 | 65 | 72 | 95 | 60 |
Used for:
·
Executive Excel reports
·
BI tools
STEP 12 — APPEND + MERGE
proc append base=factory_fraud
data=factory_lines force;
run;
proc print data=factory_fraud;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date | Report_Date | Days_From_Report | Next_Service_Date | Product_Type_Upper | Product_Type_Proper | Product_Key | Defect_Adjusted | Utilization | Fraud_Flag |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | 23407 | 31 | 23407 | ELECTRON | Electron | L01_electron | 2.5 | Good | NO |
| 2 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | 23407 | 29 | 23407 | FURNITUR | Furnitur | L02_furnitur | 3.8 | Good | NO |
| 3 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | 23407 | 27 | 23407 | ELECTRON | Electron | L03_electron | 1.2 | Excellent | NO |
| 4 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | 23407 | 26 | 23407 | AUTOMOTI | Automoti | L04_automoti | 4.9 | Average | NO |
| 5 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | 23407 | 24 | 23407 | TEXTILE | Textile | L05_textile | 5.5 | Average | NO |
| 6 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | 23407 | 22 | 23407 | ELECTRON | Electron | L06_electron | 1.5 | Excellent | NO |
| 7 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | 23407 | 21 | 23407 | FURNITUR | Furnitur | L07_furnitur | 2.9 | Good | NO |
| 8 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | 23407 | 19 | 23407 | AUTOMOTI | Automoti | L08_automoti | 6.1 | Poor | NO |
| 9 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | 23407 | 18 | 23407 | TEXTILE | Textile | L09_textile | 4.2 | Average | NO |
| 10 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | 23407 | 16 | 23407 | ELECTRON | Electron | L10_electron | 2.0 | Excellent | NO |
| 11 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | 23407 | 14 | 23407 | FURNITUR | Furnitur | L11_furnitur | 3.5 | Good | NO |
| 12 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | 23407 | 12 | 23407 | AUTOMOTI | Automoti | L12_automoti | 7.5 | Poor | YES |
| 13 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | 23407 | 11 | 23407 | TEXTILE | Textile | L13_textile | 4.8 | Average | NO |
| 14 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | 23407 | 9 | 23407 | ELECTRON | Electron | L14_electron | 1.1 | Excellent | NO |
| 15 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | 23407 | 7 | 23407 | AUTOMOTI | Automoti | L15_automoti | 8.2 | Poor | YES |
| 16 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | . | . | . | . | |||||
| 17 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | . | . | . | . | |||||
| 18 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | . | . | . | . | |||||
| 19 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | . | . | . | . | |||||
| 20 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | . | . | . | . | |||||
| 21 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | . | . | . | . | |||||
| 22 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | . | . | . | . | |||||
| 23 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | . | . | . | . | |||||
| 24 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | . | . | . | . | |||||
| 25 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | . | . | . | . | |||||
| 26 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | . | . | . | . | |||||
| 27 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | . | . | . | . | |||||
| 28 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | . | . | . | . | |||||
| 29 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | . | . | . | . | |||||
| 30 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | . | . | . | . |
proc sort data=factory_fraud;
by Line_ID;
run;
proc print data=factory_fraud;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date | Report_Date | Days_From_Report | Next_Service_Date | Product_Type_Upper | Product_Type_Proper | Product_Key | Defect_Adjusted | Utilization | Fraud_Flag |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | 23407 | 31 | 23407 | ELECTRON | Electron | L01_electron | 2.5 | Good | NO |
| 2 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | . | . | . | . | |||||
| 3 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | 23407 | 29 | 23407 | FURNITUR | Furnitur | L02_furnitur | 3.8 | Good | NO |
| 4 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | . | . | . | . | |||||
| 5 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | 23407 | 27 | 23407 | ELECTRON | Electron | L03_electron | 1.2 | Excellent | NO |
| 6 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | . | . | . | . | |||||
| 7 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | 23407 | 26 | 23407 | AUTOMOTI | Automoti | L04_automoti | 4.9 | Average | NO |
| 8 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | . | . | . | . | |||||
| 9 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | 23407 | 24 | 23407 | TEXTILE | Textile | L05_textile | 5.5 | Average | NO |
| 10 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | . | . | . | . | |||||
| 11 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | 23407 | 22 | 23407 | ELECTRON | Electron | L06_electron | 1.5 | Excellent | NO |
| 12 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | . | . | . | . | |||||
| 13 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | 23407 | 21 | 23407 | FURNITUR | Furnitur | L07_furnitur | 2.9 | Good | NO |
| 14 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | . | . | . | . | |||||
| 15 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | 23407 | 19 | 23407 | AUTOMOTI | Automoti | L08_automoti | 6.1 | Poor | NO |
| 16 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | . | . | . | . | |||||
| 17 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | 23407 | 18 | 23407 | TEXTILE | Textile | L09_textile | 4.2 | Average | NO |
| 18 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | . | . | . | . | |||||
| 19 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | 23407 | 16 | 23407 | ELECTRON | Electron | L10_electron | 2.0 | Excellent | NO |
| 20 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | . | . | . | . | |||||
| 21 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | 23407 | 14 | 23407 | FURNITUR | Furnitur | L11_furnitur | 3.5 | Good | NO |
| 22 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | . | . | . | . | |||||
| 23 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | 23407 | 12 | 23407 | AUTOMOTI | Automoti | L12_automoti | 7.5 | Poor | YES |
| 24 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | . | . | . | . | |||||
| 25 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | 23407 | 11 | 23407 | TEXTILE | Textile | L13_textile | 4.8 | Average | NO |
| 26 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | . | . | . | . | |||||
| 27 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | 23407 | 9 | 23407 | ELECTRON | Electron | L14_electron | 1.1 | Excellent | NO |
| 28 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | . | . | . | . | |||||
| 29 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | 23407 | 7 | 23407 | AUTOMOTI | Automoti | L15_automoti | 8.2 | Poor | YES |
| 30 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | . | . | . | . |
proc sort data=factory_dates;
by Line_ID;
run;
proc print data=factory_dates;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date | Report_Date | Days_From_Report | Next_Service_Date |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | 23407 | 31 | 23407 |
| 2 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | 23407 | 29 | 23407 |
| 3 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | 23407 | 27 | 23407 |
| 4 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | 23407 | 26 | 23407 |
| 5 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | 23407 | 24 | 23407 |
| 6 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | 23407 | 22 | 23407 |
| 7 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | 23407 | 21 | 23407 |
| 8 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | 23407 | 19 | 23407 |
| 9 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | 23407 | 18 | 23407 |
| 10 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | 23407 | 16 | 23407 |
| 11 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | 23407 | 14 | 23407 |
| 12 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | 23407 | 12 | 23407 |
| 13 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | 23407 | 11 | 23407 |
| 14 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | 23407 | 9 | 23407 |
| 15 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | 23407 | 7 | 23407 |
data merged_factory;
merge factory_fraud factory_dates;
by Line_ID;
run;
proc print data=merged_factory;
run;
OUTPUT:
| Obs | Line_ID | Product_Type | Units_Produced | Defect_Rate | Downtime_Hours | Energy_Consumption | Efficiency_Score | Production_Date | Report_Date | Days_From_Report | Next_Service_Date | Product_Type_Upper | Product_Type_Proper | Product_Key | Defect_Adjusted | Utilization | Fraud_Flag |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | 23407 | 31 | 23407 | ELECTRON | Electron | L01_electron | 2.5 | Good | NO |
| 2 | L01 | electron | 1200 | 2.5 | 1.2 | 450 | 88 | 01JAN2024 | . | . | . | . | |||||
| 3 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | 23407 | 29 | 23407 | FURNITUR | Furnitur | L02_furnitur | 3.8 | Good | NO |
| 4 | L02 | furnitur | 950 | 3.8 | 2.4 | 520 | 82 | 03JAN2024 | . | . | . | . | |||||
| 5 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | 23407 | 27 | 23407 | ELECTRON | Electron | L03_electron | 1.2 | Excellent | NO |
| 6 | L03 | electron | 1500 | 1.2 | 0.5 | 610 | 92 | 05JAN2024 | . | . | . | . | |||||
| 7 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | 23407 | 26 | 23407 | AUTOMOTI | Automoti | L04_automoti | 4.9 | Average | NO |
| 8 | L04 | automoti | 1800 | 4.9 | 3.8 | 900 | 75 | 06JAN2024 | . | . | . | . | |||||
| 9 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | 23407 | 24 | 23407 | TEXTILE | Textile | L05_textile | 5.5 | Average | NO |
| 10 | L05 | textile | 700 | 5.5 | 4.2 | 300 | 70 | 08JAN2024 | . | . | . | . | |||||
| 11 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | 23407 | 22 | 23407 | ELECTRON | Electron | L06_electron | 1.5 | Excellent | NO |
| 12 | L06 | electron | 1600 | 1.5 | 0.7 | 650 | 93 | 10JAN2024 | . | . | . | . | |||||
| 13 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | 23407 | 21 | 23407 | FURNITUR | Furnitur | L07_furnitur | 2.9 | Good | NO |
| 14 | L07 | furnitur | 1100 | 2.9 | 1.5 | 480 | 85 | 11JAN2024 | . | . | . | . | |||||
| 15 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | 23407 | 19 | 23407 | AUTOMOTI | Automoti | L08_automoti | 6.1 | Poor | NO |
| 16 | L08 | automoti | 1900 | 6.1 | 5.0 | 950 | 68 | 13JAN2024 | . | . | . | . | |||||
| 17 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | 23407 | 18 | 23407 | TEXTILE | Textile | L09_textile | 4.2 | Average | NO |
| 18 | L09 | textile | 800 | 4.2 | 3.0 | 350 | 74 | 14JAN2024 | . | . | . | . | |||||
| 19 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | 23407 | 16 | 23407 | ELECTRON | Electron | L10_electron | 2.0 | Excellent | NO |
| 20 | L10 | electron | 1400 | 2.0 | 1.0 | 590 | 90 | 16JAN2024 | . | . | . | . | |||||
| 21 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | 23407 | 14 | 23407 | FURNITUR | Furnitur | L11_furnitur | 3.5 | Good | NO |
| 22 | L11 | furnitur | 1000 | 3.5 | 2.0 | 500 | 83 | 18JAN2024 | . | . | . | . | |||||
| 23 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | 23407 | 12 | 23407 | AUTOMOTI | Automoti | L12_automoti | 7.5 | Poor | YES |
| 24 | L12 | automoti | 2000 | 7.5 | 6.0 | 1000 | 65 | 20JAN2024 | . | . | . | . | |||||
| 25 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | 23407 | 11 | 23407 | TEXTILE | Textile | L13_textile | 4.8 | Average | NO |
| 26 | L13 | textile | 750 | 4.8 | 3.6 | 330 | 72 | 21JAN2024 | . | . | . | . | |||||
| 27 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | 23407 | 9 | 23407 | ELECTRON | Electron | L14_electron | 1.1 | Excellent | NO |
| 28 | L14 | electron | 1700 | 1.1 | 0.4 | 680 | 95 | 23JAN2024 | . | . | . | . | |||||
| 29 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | 23407 | 7 | 23407 | AUTOMOTI | Automoti | L15_automoti | 8.2 | Poor | YES |
| 30 | L15 | automoti | 2100 | 8.2 | 7.0 | 1100 | 60 | 25JAN2024 | . | . | . | . |
Enterprise data pipelines always:
·
Append daily feeds
·
Merge reference tables
STEP 13 — DELETE TEMP DATASETS
proc datasets lib=work;
delete factory_clean factory_dates factory_util;
quit;
LOG:
Critical for:
·
Memory optimization
·
Production batch jobs
FINAL BUSINESS INSIGHTS
|
Insight |
Meaning |
|
High energy consumption reduces efficiency |
Energy optimization required |
|
Automotive lines have highest fraud risk |
Audit required |
|
Low downtime correlates with high output |
Preventive maintenance working |
|
High defect + high downtime = red flag |
Process manipulation |
CONCLUSION
This project demonstrates a complete industrial analytics lifecycle
using SAS:
·
Data ingestion
·
Cleaning
·
Feature engineering
·
Statistical modeling
·
Fraud detection
·
Visualization
·
Business interpretation
It exactly mirrors what manufacturing companies, industrial IoT teams, and operations analytics roles expect from a
SAS programmer or data analyst.
INTERVIEW QUESTIONS FOR YOU
1.How does FIRST.variable and LAST.variable work?
2.What is RETAIN and when is it used?
3.What is BY-group processing?
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 Manufacturing Industries 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 and smart cities
· EV and energy industry professionals
Comments
Post a Comment