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

I am currently using PROC surveyselect to pull a random sample from a data set using this code:

 

proc surveyselect data= out.care_statement_all_q&rptqtr. 
method=srs n=60 out=out.care_statement_q&rptqtr.; 
run;

 

Is there a way to set the size as a range.  Every run the user would like a varying sample size between 60-70.   This is part of an automated process so I would like there to be no manual involvement.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Make a random macro variable :

 

%let n=%sysevalf(%sysfunc(rand(uniform))*10+60,i);
%put NOTE: n=&n;

proc surveyselect ............... n=&n ........

View solution in original post

6 REPLIES 6
ballardw
Super User

What environment is the user using to run the code? Base SAS, Enterprise Guide, something else?

Sotarkadin
Calcite | Level 5

Sorry for the lack of details.  It is currently being run in SAS EG on our companies UNIX envrionment.  I am new to SAS programming and not sure all the correct terms.  It is executed from an auto file that kicks off automatically.

PGStats
Opal | Level 21

Create 11 fake strata in your data 

 

data fakeStrataCare;
set out.care_statement_all_q&rptqtr.;
do stratum=60 to 70;
	output;
	end;
run;

proc sort data=fakeStrataCare; by stratum; run;

and call proc surveyselect with a different sample size for each stratum

 

proc surveyselect data= fakeStrataCare 
method=srs n=(60 61 62 63 64 65 66 67 68 69 70) out=out.care_statement_q&rptqtr.; 
strata stratum;
run;

(untested)

 

PG
Ksharp
Super User

Make a random macro variable :

 

%let n=%sysevalf(%sysfunc(rand(uniform))*10+60,i);
%put NOTE: n=&n;

proc surveyselect ............... n=&n ........
Sotarkadin
Calcite | Level 5

Thank you so much Ksharp.  This worked perfectly and is simple for what I am doing.  Could you explain it a bit so if I never needed to use this again but for varying sample size.  Like if I need between 30-40 how would I change the numbers.

Ksharp
Super User
%let n=%sysevalf(%sysfunc(rand(uniform))*10+30,i);

 

int(rand('uniform')*10)  will generate the random number  0,1,2,3,4,5,6,7,8,9

 

here 10 is the range  between 30 and 40 .

here 30 is the base of range(or left value of range)  .

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
  • 6 replies
  • 1438 views
  • 0 likes
  • 4 in conversation