BookmarkSubscribeRSS Feed
whymath
Lapis Lazuli | Level 10

I am simulating data for a 2-groups trial with 100 subjects in each group. There are four variables: GROUP, SUBJNO, SEX, AGE. SEX and AGE are covariates for following model.

Here is my code:

 

%let seed=12345;

data tab1;
  call streaminit(&seed.);
  length subjno $4 sex $1;
  do _n_=1 to 100;
    group=1;
    subjno='1'||put(_n_,z3.);
    sex=choosec(rand('table',0.5,0.5),'M','F');
    age=rand('integer',18,70);
    output;
  end;

  do _n_=1 to 100;
    group=2;
    subjno='2'||put(_n_,z3.);
    sex=choosec(rand('table',0.5,0.5),'M','F');
    age=rand('integer',18,70);
    output;
  end;
run;

 

Unfortunately, The initial random seed, 12345, causes SEX statistical difference on different group, the p value of Chisq is 0.0477.

 

I have tried new seed value like 123, 1234, 123456, 1234567 and they will not cause SEX statistical difference on different group. 

I know there is a possibility that statistical difference of covariates happens. Is there a way to ensure no statistical differences between groups in covariates when simulating data?

Maybe block randomization with covariates as block factor? What about continous covariate variable like AGE?

 

 

 

 

3 REPLIES 3
Ksharp
Super User

You want this ?

proc plan seed=123;
factors group=2 ordered subj=100 /noprint;
output out=tab1;
quit;
data tab2;
set tab1;
if subj in (1:50) then sex='F';
 else sex='M';
run;
proc freq data=tab2;
table group*sex/ chisq;
run;

Ksharp_0-1748597192795.png

 

whymath
Lapis Lazuli | Level 10
Thank you for your reply, would 50:50 be kind of sedulously? And what about continous covariate variable like AGE?
Ksharp
Super User
Not really,you could use 49: 51 or 48:52 .
About AGE you could try NORMAL distribution other than uniform distribution.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 392 views
  • 0 likes
  • 2 in conversation