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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 1892 views
  • 2 likes
  • 2 in conversation