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

I am using proc surveyselect to select a random sample of 250 people from the dataset called baseline_followup. I then modify the new random sample to assign everyone a value of 0 for the Ycat variable. I merge the new dataset i named control2 with existing dataset called case. I then go ahead to find the odds ratio of the variables xcat and ycat. 

 

is there a way to run this same code 100 times and find the average odds ratio? because surveyselect will always randomly selected different people. So I want to calculate the 100 different odds ratios and find the average. 

 

Any help is appreciated! 

 

below is the code

 

proc surveyselect data=baseline_followup 
out=control2
method= srs
sampsize=250;
run;

 

data control2;
modify control2;
Ycat=0;
run;

 

data casecontrol2; 
set case control2; 
run;

 

proc freq data=casecontrol2 order=formatted;
table xcat*ycat/relrisk;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
amin1234
Obsidian | Level 7

Thank you all for your responses and ideas! This is how I finally solved it.

--------------------------------------------------------------------------------------

 

%MACRO domean;
%DO I = 1 %TO 100;
proc surveyselect data=baseline_followup
out=controlmac&i
method= srs
sampsize=250;
run;

data controlmac&i;
modify controlmac&i;
Ycat=0;
run;

data casecohort&i;
set case controlmac&i;
run;

ods trace on;
proc freq data=casecohort&i order=formatted;
table xcat*ycat/relrisk;
run;

ods trace off;

ods output RelativeRisks=Output&i;
proc freq data=casecohort&i order=formatted;
table xcat*ycat/relrisk;
run;

proc print data=Output&i noobs;
run;

%END;
%MEND domean;


%domean

data allrelrisk; set output1-output100;
run;

data onlyodds; set allrelrisk;
where studytype not like 'Co%)';
run;

proc means mean data=onlyodds;
run;

View solution in original post

4 REPLIES 4
pau13rown
Lapis Lazuli | Level 10

can you not generate eg 1000 random samples and then use a by statement (by samp) in the proc freq?

amin1234
Obsidian | Level 7

Thank you @pau13rown for your reply. Yes, I can generate 100 random samples. It combines all of them into one dataset. So i can run a proc freq in addition with a by statement to see the frequencies for each replicate. However, I combine the new 100 random samples with another dataset. Replicate values are missing. and so i do not know how to calculate the odds ratio of that. I will appreciate it if you can post a sample code of any method or ideas. 

PGStats
Opal | Level 21

Use OUTHITS in the surveyselect statement to get separate copies of replicates. Or use a weight numberhits; statement in proc freq.

PG
amin1234
Obsidian | Level 7

Thank you all for your responses and ideas! This is how I finally solved it.

--------------------------------------------------------------------------------------

 

%MACRO domean;
%DO I = 1 %TO 100;
proc surveyselect data=baseline_followup
out=controlmac&i
method= srs
sampsize=250;
run;

data controlmac&i;
modify controlmac&i;
Ycat=0;
run;

data casecohort&i;
set case controlmac&i;
run;

ods trace on;
proc freq data=casecohort&i order=formatted;
table xcat*ycat/relrisk;
run;

ods trace off;

ods output RelativeRisks=Output&i;
proc freq data=casecohort&i order=formatted;
table xcat*ycat/relrisk;
run;

proc print data=Output&i noobs;
run;

%END;
%MEND domean;


%domean

data allrelrisk; set output1-output100;
run;

data onlyodds; set allrelrisk;
where studytype not like 'Co%)';
run;

proc means mean data=onlyodds;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 4 replies
  • 2822 views
  • 1 like
  • 3 in conversation