Published on :
Statistics CREATION_INTERNE

Student's t-test on simulated data

This code is also available in: Deutsch Español Français
Awaiting validation
This script starts by creating a SAS© table named QUES6_4 containing simulated data for three groups (A, B, C) with randomly generated numerical variables X and Y. Then, a TTEST procedure is used to compare the means of variables X and Y specifically between groups A and C.
Data Analysis

Type : CREATION_INTERNE


The data is entirely generated in the DATA step using DO loops and random number functions (RANNOR, RANUNI).

1 Code Block
DATA STEP Data
Explanation :
Creation of the QUES6_4 table. Nested loops are used to generate 10 observations for each of groups A, B, and C. Variables X and Y are calculated using random functions (normal distribution and uniform distribution).
Copied!
1DATA QUES6_4;
2 DO GROUP = 'A','B','C';
3 DO I = 1 TO 10;
4 X = ROUND(RANNOR(135)*10 + 300 +
5 5*(GROUP EQ 'A') - 7*(GROUP EQ 'C'));
6 Y = ROUND(RANUNI(135)*100 + X);
7 OUTPUT;
8 END;
9 END;
10 DROP I;
11RUN;
2 Code Block
PROC TTEST
Explanation :
Execution of a Student's t-test to compare means. The WHERE clause filters the data to retain only groups A and C. The CLASS statement defines the grouping variable, and VAR specifies the variables to be analyzed.
Copied!
1PROC TTEST;
2 title 'Problem 6.4';
3 where GROUP in ('A' 'C');
4 class GROUP;
5 var X Y;
6RUN;
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.