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;
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;
can you not generate eg 1000 random samples and then use a by statement (by samp) in the proc freq?
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.
Use OUTHITS in the surveyselect statement to get separate copies of replicates. Or use a weight numberhits; statement in proc freq.
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;
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.
Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.