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-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!

New Learning Events in April

 

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.

LEARN MORE

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