turn on suggestions

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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- random sample from another data set

Topic Options

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

Highlighted
# random sample from another data set

[ Edited ]
Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Thursday - last edited Sunday

I have no idea how to get started on this. I was thinking of creating an array with DO LOOPS to get the observation but not sure

where to start it as I am very new to SAS.

Please let me know if you need anything else. I will be attaching a sample of my code soon.

Thanks!

Accepted Solutions

Solution

Friday

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to at803535

Friday - last edited Friday

I would probably do this in two distinct PROC SURVEYSELECT steps like below.

I made example data set from sashelp.cars and made arbitrary mileage categories for demonstration purposes

```
data cars;
set sashelp.cars;
length mileage $20;
if mpg_city<16 then mileage='Bad';
else if 16<=mpg_city<25 then mileage='Fair';
else if 25<=mpg_city<30 then mileage='Good';
else mileage='Excellent';
do i=1 to 100; output; end;
drop i;
run;
proc sort data=cars;
by mileage;
run;
proc surveyselect data=cars out=sample1 method=srs n=200 noprint;
where mileage in ('Bad', 'Excellent');
strata mileage;
run;
proc surveyselect data=cars out=sample2 method=srs samprate=0.01 noprint;
where mileage in ('Fair', 'Good');
strata mileage;
run;
data finalsample;
set sample1 sample2;
run;
```

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to at803535

Thursday

Try PROC SURVEYSELECT

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to at803535

Friday

Look at the **strata statement** and the **Secondary input dataset** feature of **proc surveyselect**.

PG

Solution

Friday

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to at803535

Friday - last edited Friday

I would probably do this in two distinct PROC SURVEYSELECT steps like below.

I made example data set from sashelp.cars and made arbitrary mileage categories for demonstration purposes

```
data cars;
set sashelp.cars;
length mileage $20;
if mpg_city<16 then mileage='Bad';
else if 16<=mpg_city<25 then mileage='Fair';
else if 25<=mpg_city<30 then mileage='Good';
else mileage='Excellent';
do i=1 to 100; output; end;
drop i;
run;
proc sort data=cars;
by mileage;
run;
proc surveyselect data=cars out=sample1 method=srs n=200 noprint;
where mileage in ('Bad', 'Excellent');
strata mileage;
run;
proc surveyselect data=cars out=sample2 method=srs samprate=0.01 noprint;
where mileage in ('Fair', 'Good');
strata mileage;
run;
data finalsample;
set sample1 sample2;
run;
```