Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- How to have a varying sample size in PROC surveyselect.

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-09-2016 12:59 PM
(1171 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Make a random macro variable :

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

6 REPLIES 6

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Make a random macro variable :

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

`%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 is headed **back** to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

**Interested in speaking?** Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

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.