BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tpham
Quartz | Level 8

In my dataset from an actual clinical trial, I have 64 ID numbers (numbered 1 to 64), where 32 goes to treatment group A and 32 goes to treatment B and a score (outcome)

So I want to add a hypothetical variable where I want to generate a variable (let's call it Gender/Sex, so 2 levels)  that is sex is evenly and randomly distributed within each group (16 males and 16 females per treatment group). How do I do this randomly?

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

If you use survey select you can name your strata:

proc surveyselect data='trial' method=srs n= 'sample size'

      seed= 'number' out='trial sample;

strata  "enter strata here, gender sex with no column, try both and see what gives you the desired output"

run;

I put everything you'll need to type in quotes.  Hope this helps.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, that statisticians out there probably have the best answers for this.  My way would be:

data want;

     call streaminit(123);

     set have;

     male_cnt=0;

     female_cnt=0;

     if rand("uniform") <0.5 then do;

          if male_cnt <16 then do;

               sex="male";

               male_cnt=male_cnt+1;

          end;

          else do;

               sex="female";              

               female_cnt=female_cnt+1;

     end;

     else do;

          /* same as above but reveresed */

     end;

run;

Probably a bit simplistic and not so random, but if it doesn't matter too much...


Steelers_In_DC
Barite | Level 11

If you use survey select you can name your strata:

proc surveyselect data='trial' method=srs n= 'sample size'

      seed= 'number' out='trial sample;

strata  "enter strata here, gender sex with no column, try both and see what gives you the desired output"

run;

I put everything you'll need to type in quotes.  Hope this helps.

Tpham
Quartz | Level 8

thanks that worked for me. I used that to randomly select the men.. and then if the sex variable is missing, i pop recoded that to women.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2582 views
  • 0 likes
  • 3 in conversation