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
- /
- SAS Procedures
- /
- How to set sampsize as count of table/4

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

08-28-2013 07:41 AM

Hi I want to get a random sample from a table but I want output number as %25 of the table count

here is the code:

proc surveyselect data=temp.tableA method = urs sampsize = ???

rep=1 seed=12345 out=temp.sonuc out=outhits;

id bayi pos key msisdn;

run;

proc print data = temp.sonuc noobs;

run;

how can I put sampsize=count(tableA)/4

or the %25

for example table has 1000 row

but I need output number 250

but I do not put it hard coded

it must calculate the count of table then it must take 1/4 of the numberr

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

08-28-2013 07:53 AM

You could create a macro variable based on the number of obs in the dataset using the following.

%LET DSID = %SYSFUNC(OPEN(SASHELP.CLASS));

%LET NUMOBS = %SYSFUNC(ATTRN(&DSID.,NOBS));

%LET SAMP = %SYSEVALF(&NUMOBS./4,CEIL);

%LET RC = %SYSFUNC(CLOSE(&DSID));

%PUT *****************************&NUMOBS. &SAMP.;

Edited to make use of the CEIL modifier.

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

08-28-2013 08:20 AM

thank you but I do not know how to write macro yet

but I will learn in near future

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

08-28-2013 07:56 AM

You need to use the SAMPRATE option instead of SAMPSIZE.

proc surveyselect data=temp.tableA method = urs samprate = 0.25

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

08-28-2013 08:18 AM

I made what you said but it brings to me not exactly 1/4 of the table

for example my table has 425019 row

but the code brings to me 94239 row

I changed the extra features from the code but it did not change

proc surveyselect data=temp.tableA method = urs samprate = 0.25

seed=12345 out=temp.sonuc ;

run;

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

08-28-2013 08:38 AM

This is due to the sampling method you are using (URS), which allows replacement (i.e. it can select the same observation more than once). The output dataset will only contain the unique values, so any duplicate observations have been dropped. If you change the method to SRS then you will always get 25% of the observations each time.

I suggest you read up on the PROC SURVEYSELECT documentation, this gives you all the answers to your questions.

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

08-28-2013 08:50 AM

Thank you very much,

I will read of course but this was urgent.

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

08-28-2013 09:27 AM

I would never trust an urgent need to the whims of a user forum.

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

08-28-2013 09:44 AM

Likewise I would never run some SAS code without understanding what it was doing!

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

08-28-2013 08:00 AM

Can't you SAMPRATE= option.

**SAMPRATE= r **

**RATE= r **

specifies the sampling rate, which is the proportion of units to select for the sample. The sampling rate *r* must be a positive number. You can specify *r* as a number between 0 and 1. Or you can specify *r* in percentage form as a number between 1 and 100, and PROC SURVEYSELECT converts that number to a proportion. The procedure treats the value 1 as 100% instead of 1%.