BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

I am randomly picking up the samples(a) using PROC SURVEYSELECT and now
I want to pick up 10% control group from the samples picked up earlier and dont want to mix up this Control samples(b) with final data.For this do I need to pick up (b) also by proc surveyselect and merge (b) with (a) and take out them from final data or is there any other way? through which I can do in a single or simple steps
and avoid heavy programming.
If anyone can Please help me.
Thank You in advance.
4 REPLIES 4
deleted_user
Not applicable
Hello Maithilli,

Could this be a solution to your problem?

proc surveyselect sampsize=200 data=sashelp.cars out=T01_sample;
run;

* CG=control group and RS=Rest of sample;
data T02_sample;
set T01_sample;
if ranuni(0) le 0.1
then set="CG";
else set="RS";
run;

* To check that you have approximately 10% of your sample in Control Group;
proc freq data=T02_sample;
tables set;
run;

Best regards,

Yoba Message was edited by: yoba
deleted_user
Not applicable
Thank You alot Yoba.I'll try this.
deleted_user
Not applicable
Hello Maithili,

There is a more "elegant" way to handle this kind of problem, I think. The trick is to "unsort" the original dataset. Of course, I would'nt recommend to do that if your orginal dataset is very large because sorting is involved. What is nice is that you simply add a flag to your original population indicating where the "record goes".

Here is an example. You'll have exactly 100 observations in the control group, 400 in the rest of sample and the rest would'nt be selected.

Here is the example:

data T01_population;
do i=1 to 10000;
output;
end;
run;

proc sql;
create table T02_population_unsorted as
select *
from T01_population
order by ranuni(0);
quit;

data T03_groups;
set T02_population_unsorted;
select;
when(_N_ le 100) group='CG';
when(_N_ le 500) group='RS';
otherwise group='--';
end;
run;

Other possibility: you use a probability to decide "where the record goes". Even faster. You don't need to sort the dataset.

data T03_groups;
set T01_population;
select;
when(ranuni(0) le 0.1 ) group='CG';
when(0.1 lt ranuni(0) le 0.2) group='RS';
otherwise group='--';
end;
run;

There are many other possibilities that would apply if the population is verrrryyyyy large, for example or if you want to extend it to stratified sampling or ... Let me know if you need further help.

Best regards,

Yoba
deleted_user
Not applicable
Yoba,

Thank you very much.This helped me alot.

Regards,
Maithili

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 713 views
  • 0 likes
  • 1 in conversation