How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

I have been searching for a way to pass the sample size to proc surveyselect when the sample is not strata.  the "n" or sampsize only takes integers in the proc surveyselect.  I looked to pass the sample size using proc sql outobs= .... but outobs only takes integers also.  The sample size is calculated and is called samplesize

 

proc surveyselect data=datain sampsize=samplesize out=dataout;

run;

 

I even thought to use a do loop and pass the sample size to the do loop.  I have not found a way.  How do we pass the sample size to any proc or is there another way to do this?


Accepted Solutions
Solution
‎02-28-2016 08:11 PM
Super User
Posts: 19,167

Re: How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

Also, have you considered samprate instead of sampsize? Then you can pass the 10% in directly.

View solution in original post


All Replies
Super User
Posts: 19,167

Re: How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

I'm confused. A record is whole, so only integers make sense in the list. 

 

What exactly are you trying to do? Why not round your values in the calculation?

 

Sampsize also takes a dataset so you can specify it in that manner, or  if a single number a macro variable.  But the restriction on whole numbers makes sense. 

Occasional Contributor
Posts: 19

Re: How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

Reeza,

 

I want to select 10% of my observations and pass that number to proc surveyselect to limit the # of observations.  the question marks below in the snippet of code are were I want to place a variable so the "n" or "sampsize" is equal to the value in the variable.  In this case that variable is called nsize.  The same problem is presented when using proc sql outobs=????.  By design it appears i can only place an integer.  So "how?" without hard coding in the integer can I pass a value to a variable to get different sample sizes? 

 

data datain;

infile '/folders/myfolders/datain.txt' dlm='09'X end=eof;

input gender age systolic diastolic;

count + 1;

if eof=1 then

 do nsize=round(count * .10);

  call symput ("samplesize", nsize);

 end;

run;

 

proc surveyselect data=datain n=???? out=dataout;

run

 

OR 

 

proc surveyselect data=datain sampsize=????? seed=-1 out=dataout;

run;

Super User
Posts: 19,167

Re: How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

I'm still confused.
Are you trying to get multiple samples of different sizes?

Otherwise isn't this all you need:
Sampsize = &samplesize
Solution
‎02-28-2016 08:11 PM
Super User
Posts: 19,167

Re: How to pass sample size as a variable to PROC SURVEYSELECT OR PROC SQL OUTOBS

Also, have you considered samprate instead of sampsize? Then you can pass the 10% in directly.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 409 views
  • 4 likes
  • 2 in conversation