Help using Base SAS procedures

Dynamic sampsize in proc surveyselect

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Dynamic sampsize in proc surveyselect

[ Edited ]

I am using proc surveyselect for unrestricted random sampling, my code is as follows:

 


proc surveyselect data=A out=B
     seed = 1234 method = urs
	 sampsize=237 /* This is the number of rows of a dataset called C, which has already been created*/
     outhits rep = 1;
run;
ods listing close;

 

My input datafile is called A and output datafile is called B.

 

I have another dataset called C (which is different from the input file A) and it has 237 rows, i.e., 237 observations for each variable. Instead of manually inputting the number 237, I want the sampsize to be equal to the number of rows of dataset C (since the number of rows of this dataset will change depending on the data I use). How can I do this?

 

Thanks


Accepted Solutions
Solution
‎01-05-2016 01:28 PM
Super User
Posts: 17,784

Re: Dynamic sampsize in proc surveyselect

proc sql noprint;
select count(*) into :record_count
from c;
quit;

%put &record_count;

proc surveyselect data=a out=b
     seed = 1234 method = urs
sampsize=&record_count /* This is the number of rows of a dataset called C, which has already been created*/
     outhits rep = 1;
run;

View solution in original post


All Replies
Super User
Posts: 17,784

Re: Dynamic sampsize in proc surveyselect

Rather than sampsize use samprate=1

 

proc surveyselect data=sashelp.class out=class
     seed = 1234 method = urs
samprate=1 /* This is the number of rows of a dataset called C, which has already been created*/
     outhits rep = 1;
run;
Occasional Contributor
Posts: 12

Re: Dynamic sampsize in proc surveyselect

But doesn't samprate=1 create a sample size equal to the size of the INPUT datafile? In my case, the input datafile is called "A", but I want the size to be equal to that of a datafile called "C", which is NOT the input data; they have different sizes.

 

How can I achieve this?

Super User
Posts: 17,784

Re: Dynamic sampsize in proc surveyselect

Then I would suggest a macro variable to get the size of dataset C and use that in your proc surveyselect. Sampsize/Samprate also take datasets so you could create a dataset with the information as well.
Occasional Contributor
Posts: 12

Re: Dynamic sampsize in proc surveyselect

Thanks, this is what I was thinking of, however I am quite new to SAS. Any chance you can provide a skeleton template code for me to edit?

 

Cheers.

Solution
‎01-05-2016 01:28 PM
Super User
Posts: 17,784

Re: Dynamic sampsize in proc surveyselect

proc sql noprint;
select count(*) into :record_count
from c;
quit;

%put &record_count;

proc surveyselect data=a out=b
     seed = 1234 method = urs
sampsize=&record_count /* This is the number of rows of a dataset called C, which has already been created*/
     outhits rep = 1;
run;
☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 451 views
  • 2 likes
  • 2 in conversation