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.
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!
DATA Test_Matrix; SET Test_Matrix;
Mean = ROUND(Mean, .1);
Sigma = ROUND(Sigma, .1);
RUN;
PROC SORT DATA=Test_Matrix; BY Vendor Month; RUN;
1
DATA Test_Matrix; SET Test_Matrix;
2
Mean = ROUND(Mean, .1);
3
Sigma = ROUND(Sigma, .1);
4
RUN;
5
PROC SORTDATA=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!
DATA RECORDS; SET TEST_MATRIX;
DO Unit=1 TO Num;
OUTPUT;
END;
RUN;
1
DATA RECORDS; SET TEST_MATRIX;
2
DO Unit=1 TO Num;
3
OUTPUT;
4
END;
5
RUN;
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!
%let D=500; %let D=7500; %LET D = 50000; %let B = 1;
DATA Import_This; SET RECORDS; retain SEED0 SEED1 SEED2 SEED3;
FORMAT Test_Time $25. Delay $12. Del 8.0 Resistance 8.2 Result $8. Fail 8.0;
FORMAT TestTime DATETIME20. TestDate MMDDYY10.;
TestTime=MDY(Month, min(30,Unit), 2008)*60*60*24;
TestDate=DATEPART(TestTime);
Test_Time=PUT(TestTime, DateTime20.);
IF Vendor="Empirical Engineering" THEN Test_Time=PUT(TestDate, MMDDYY10.);
if _N_=1 then do; SEED0=12345; SEED1=54321; SEED2=15243; SEED3=34251; END;
CALL RANNOR(SEED0, Z);
Resistance = Mean + Sigma*Z;
FORMAT Result $8.;
Result = "Pass"; Fail=0;
IF Resistance < 12.5 THEN Result="Fail Low";
IF Resistance > 22.5 THEN Result="Fail Hi";
IF Result ne "Pass" THEN Fail=1;
CALL RANNOR(SEED1, De);
Del = DA + DB*Resistance + .2*Resistance**2 + D_Sig*De;
Delay=PUT(Del, 8.0);
IF Vendor="Duality Logic" THEN DO;
IF Month=12 AND Unit>20 THEN Delay="N/A";
END;
IF Vendor="Empirical Engineering" THEN DO;
IF Month=4 AND Unit>10 THEN Delay="N/A";
END;
FORMAT Defects 8.0;
CALL RANPOI(Seed3, Rate, Defects);
DROP Mean Sigma Z Num DA DB D_Sig De Rate
SEED0 SEED1 SEED2 SEED3
TestTime TestDate Del Defects;
RUN;
1
%let D=500; %let D=7500; %LET D = 50000; %let B = 1;
2
DATA Import_This; SET RECORDS; retain SEED0 SEED1 SEED2 SEED3;
3
FORMAT Test_Time $25. Delay $12. Del 8.0 Resistance 8.2RESULT $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_=1THENDO; SEED0=12345; SEED1=54321; SEED2=15243; SEED3=34251; END;
10
CALL RANNOR(SEED0, Z);
11
Resistance = Mean + Sigma*Z;
12
13
14
15
16
FORMATRESULT $8.;
17
RESULT = "Pass"; Fail=0;
18
IF Resistance < 12.5THENRESULT="Fail Low";
19
IF Resistance > 22.5THENRESULT="Fail Hi";
20
IFRESULT 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"THENDO;
25
IF Month=12 AND Unit>20THEN Delay="N/A";
26
END;
27
IF Vendor="Empirical Engineering"THENDO;
28
IF Month=4 AND Unit>10THEN 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;
37
RUN;
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.
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.
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.