BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TrueTears
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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

5 REPLIES 5
Reeza
Super User

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;
TrueTears
Obsidian | Level 7

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?

Reeza
Super User
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.
TrueTears
Obsidian | Level 7

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.

Reeza
Super User
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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