Published on :
ETL CREATION_INTERNE

Generation of test data for process simulation

This code is also available in: Deutsch Español Français
Awaiting validation
The script proceeds in several steps. First, it creates a 'Test_Matrix' table with basic parameters for three vendors over 12 months. It then extends this table into a 'RECORDS' table to simulate individual test units. The main step, in the 'Import_This' table, generates detailed test data (resistance, delay, defects) using random number generation functions (RANNOR, RANPOI) to simulate a statistical distribution. Finally, the script cleans up intermediate tables, exports the final result to a CSV file, and re-imports it for verification.
Data Analysis

Type : CREATION_INTERNE


All data is synthetically generated within the script. No external data source is read. Generation starts with a DO loop to create a parameter table, which is then extended and enriched with random data to simulate a real process.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block initializes the 'Test_Matrix' table. It iteratively generates simulation parameters (Num, Mean, Sigma, etc.) for 3 different vendors ('Vendor') over a 12-month period.
Copied!
1DATA Test_Matrix; LENGTH Vendor $21.;
2 DO Month=1 TO 12;
3 Mon="2008-"||PUT(Month, Z2.0);
4 Num=20+3*INT(Month/3); Mean=18; Sigma=2; DA=120; DB=.75; D_Sig=10;
5 Rate=.75; Vendor="ChiTronix Components"; OUTPUT;
6 Num=25+INT(Month/3); Mean=17; Sigma=2+(Month/12); DA=120; DB=2; D_Sig=20;
7 Rate=4-Month/4; Vendor="Duality Logic"; OUTPUT;
8 Num=15; Mean=13; Sigma=3; DA=140; DB=.5; D_Sig=15;
9 Rate=ROUND(1+Month/3, .1); Vendor="Empirical Engineering"; OUTPUT;
10 END;
11RUN;
2 Code Block
DATA STEP
Explanation :
This block modifies the 'Test_Matrix' table by rounding the values of the 'Mean' and 'Sigma' variables. It is followed by a PROC SORT to sort the data by vendor and month, in preparation for the next steps.
Copied!
1DATA Test_Matrix; SET Test_Matrix;
2 Mean = ROUND(Mean, .1);
3 Sigma = ROUND(Sigma, .1);
4RUN;
5PROC SORT DATA=Test_Matrix; BY Vendor Month; RUN;
3 Code Block
DATA STEP Data
Explanation :
This DATA STEP reads the 'Test_Matrix' table and uses it to generate the 'RECORDS' table. A 'DO Unit=1 TO Num' loop is used to duplicate records and thus create a row for each 'unit' to be tested.
Copied!
1DATA RECORDS; SET TEST_MATRIX;
2 DO Unit=1 TO Num;
3 OUTPUT;
4 END;
5RUN;
4 Code Block
DATA STEP Data
Explanation :
This is the main data generation block. It reads the 'RECORDS' table and creates 'Import_This'. Test variables like 'Resistance', 'Delay', and 'Defects' are simulated using random number functions (RANNOR, RANPOI) based on the defined parameters. Formats are applied and intermediate variables are dropped at the end.
Copied!
1%let D=500; %let D=7500; %LET D = 50000; %let B = 1;
2DATA Import_This; SET RECORDS; retain SEED0 SEED1 SEED2 SEED3;
3 FORMAT Test_Time $25. Delay $12. Del 8.0 Resistance 8.2 RESULT $8. Fail 8.0;
4 FORMAT TestTime DATETIME20. TestDate MMDDYY10.;
5 TestTime=MDY(Month, min(30,Unit), 2008)*60*60*24;
6 TestDate=DATEPART(TestTime);
7 Test_Time=PUT(TestTime, DateTime20.);
8 IF Vendor="Empirical Engineering" THEN Test_Time=PUT(TestDate, MMDDYY10.);
9 IF _N_=1 THEN DO; SEED0=12345; SEED1=54321; SEED2=15243; SEED3=34251; END;
10 CALL RANNOR(SEED0, Z);
11 Resistance = Mean + Sigma*Z;
12 
13
14 
15 
16 FORMAT RESULT $8.;
17 RESULT = "Pass"; Fail=0;
18 IF Resistance < 12.5 THEN RESULT="Fail Low";
19 IF Resistance > 22.5 THEN RESULT="Fail Hi";
20 IF RESULT ne "Pass" THEN Fail=1;
21 CALL RANNOR(SEED1, De);
22 Del = DA + DB*Resistance + .2*Resistance**2 + D_Sig*De;
23 Delay=PUT(Del, 8.0);
24 IF Vendor="Duality Logic" THEN DO;
25 IF Month=12 AND Unit>20 THEN Delay="N/A";
26 END;
27 IF Vendor="Empirical Engineering" THEN DO;
28 IF Month=4 AND Unit>10 THEN Delay="N/A";
29 END;
30 
31
32 FORMAT Defects 8.0;
33 CALL RANPOI(Seed3, Rate, Defects);
34 DROP Mean Sigma Z Num DA DB D_Sig De Rate
35 SEED0 SEED1 SEED2 SEED3
36 TestTime TestDate Del Defects;
37RUN;
5 Code Block
PROC DATASETS
Explanation :
This block uses the PROC DATASETS procedure to delete intermediate work tables ('Test_Matrix' and 'Records') that are no longer needed, in order to clean up the working environment.
Copied!
1 
2PROC DATASETS LIBRARY=WORK GENNUM=ALL NOLIST;
3DELETE Test_Matrix Records;
4RUN;
5 
6QUIT;
7 
6 Code Block
PROC EXPORT Data
Explanation :
This final block exports the 'Import_This' table to a CSV file using PROC EXPORT. The output file path depends on the '&JES' macro variable. Immediately after, PROC IMPORT is used to read the same CSV file and create a new SAS table named 'Import', demonstrating an export-import cycle.
Copied!
1PROC EXPORT DATA=Import_This
2 OUTFILE ="&JES.input_data/import_this.csv" REPLACE;
3RUN;
4 
5PROC IMPORT DATAFILE="&JES.input_data/import_this.csv"
6 OUT =Import REPLACE;
7RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.