Help using Base SAS procedures

Proc Survey select - Random sampling

Reply
New Contributor
Posts: 4

Proc Survey select - Random sampling

Hello,

          I'm trying to sample data into development sample and validation sample using proc surveyselect, but the output shown is not sampled returning the same original dataset.The code I used is

 

proc surveyselect data=stores1 out=devsample method=srs samprate=0.5 outall;

run;

 

 

I also used ranuni function but the result is same , no sampling is done

    data devsample;

    set stores1;

    if ranuni(100)<0.50 then output=devsample;

    run;

please correct me where I went wrong 

 

 

Super Contributor
Posts: 336

Re: Proc Survey select - Random sampling

Both seem o.k. (remove "=" from the 2nd program). Do you get an error? Could stores1 be empty? ..

 

Data Stores1;
  Do ID1=1 To 30;
    Do ID2=1 To 30;
      Value=Ranuni(1);
	  Output;
	End;
  End;
Run;

proc surveyselect data=stores1 out=devsample method=srs samprate=0.5 outall;
run;

data devsample2;
  set stores1;
  if ranuni(100)<0.50 then output devsample2; * remove equal sign!;
run;
New Contributor
Posts: 4

Re: Proc Survey select - Random sampling

what happens when '=' is used ?

Super Contributor
Posts: 336

Re: Proc Survey select - Random sampling

If you use '=', you create a variable with the name 'output'. Then a second variable is created with the file name 'devsample'. Because there are no entries for 'devsample', in effect you are creating 2 variables with missing values, and write it to the (/all) data files declared in the DATA-statement at the beginning.

Trusted Advisor
Posts: 1,204

Re: Proc Survey select - Random sampling

Hi,

 

proc surveyselect data=stores1 out=devsample method=srs samprate=0.5 outall;

run;

 

outall option creates a variable "selected" that provides a flag to separate two data sets. You need a data step to create two data sets. Please try this after proc surveyselect:

 

data develop validate;
set devsample;
if selected then output develop;
else output validate;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 344 views
  • 6 likes
  • 3 in conversation