Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem selecting a sample - might need lag function

Status
Not open for further replies.

swmarlow

Technical User
May 3, 2009
2
GB
I need some sas code for the following urgently.
I have 2 variables id and C that might look like
id C
1 1
2 2
3 3.2
4 4.6
5 5.8
6 6.9
7 8.4
. .
. .
n 546.4

First, I need to generate a random start R, between O and l.
I then need to select case ids from the list where C is R, R+l, R+2l,....
Usually C will not equal exactly R, R+l, R+2l, ... in which case choose the case id whose value of C is slightly greater than R, R+l, R+2l,...

For example, if l=3.2 and R=0.2:
then select case ids where C=0.2, 3.4, 6.6,...
therefore choose case ids where C=1, 4.6, 6.9,...
ie where id=1,4,6,..

Can you help?
 
Are you just trying to get a random sample?
You can use Proc Surveryselect for that.

Code:
proc surveyselect data=Full_List method=srs n=50 out=Sample_List;
run;
Method srs = Simple random selection
N = number of samples you want

If you want samples that equal a certain percentage of your data you can have a data step before this that returns the number of rows in your table, multiple by your percent, then set that number as a macro variable and carry it over into the N= part of the procedure.

As far as answering your question, I'm not sure how to do everything you asked, but I know you can get a random number between 0 and 1 with:
Code:
data getnumber;
x=uniform(1);
run;

Hope some of this is helpful.
Dave
 
Thank you Dave. I am aware of proc surveyselect but I really do need to use the sampling method as I have described (one of the reasons is that C is related to l). Any thoughts anyone?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top