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
- /
- General Programming
- /
- Split sample into N subsamples with equal number o...

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

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

11-08-2013 05:50 PM

Hello Everyone,

I have a large sample and I want to split it into subsamples (new files) with equal number of observation to process one by one.

So say in the below sample with 10 obs, how can I ask SAS to make a 5 NEW FILEs A1 A2 A3 A4 A5 , each has 2 obs.

I can do the calculation of number obs and number of subsample manually myself.

Thank you for your help.

HHC

data a;

input id value;

datalines;

1 2

2 3

3 2

4 6

5 9

6 6

7 95

8 9

9 12

10 1

;run;

Accepted Solutions

Solution

11-08-2013
05:57 PM

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

Posted in reply to hhchenfx

11-08-2013 05:57 PM

If you want to add a grouping variable one way would be:

groupid = mod(_n_,number of groups);

Which will mark every nth record. If your dataset is not an exact multiple of n then you will have one more record for some groups.

The default values will go 0 to n-1, if you want 1 to n then add 1:

groupid = 1+ mod(_n_,number of groups);

All Replies

Solution

11-08-2013
05:57 PM

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

Posted in reply to hhchenfx

11-08-2013 05:57 PM

If you want to add a grouping variable one way would be:

groupid = mod(_n_,number of groups);

Which will mark every nth record. If your dataset is not an exact multiple of n then you will have one more record for some groups.

The default values will go 0 to n-1, if you want 1 to n then add 1:

groupid = 1+ mod(_n_,number of groups);