- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 11-05-2008 08:41 AM
(863 views)
hi all,
How we can generate random numbers between a specified range?
Ex: I want to create count=23 to 64 randomly in a dataset which contains 200 observation. How?
It should be generic. Means write with macros. Just user need to give start, end values.
I tried like this:
Count=ceil(ranuni(0)*42)+22;
This is correct for that range only !
If range is changed, we need to change the code.
I want this with macro code, so that it will generate required range only !
Example code…
%macro a;
Data qwe;
Do i=1 to 200;
Count= --------------- -? --> fill this statement.
Output;
End;
Run;
%mend;
%a(start=23,end=64);
How we can generate random numbers between a specified range?
Ex: I want to create count=23 to 64 randomly in a dataset which contains 200 observation. How?
It should be generic. Means write with macros. Just user need to give start, end values.
I tried like this:
Count=ceil(ranuni(0)*42)+22;
This is correct for that range only !
If range is changed, we need to change the code.
I want this with macro code, so that it will generate required range only !
Example code…
%macro a;
Data qwe;
Do i=1 to 200;
Count= --------------- -? --> fill this statement.
Output;
End;
Run;
%mend;
%a(start=23,end=64);
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
go the answer:
%macro a(a,b,c);
Data qwe;
Do i=1 to &c;
Count= ceil(ranuni(0)*(&b-&a))+&a;
Output;
End;
Run;
%mend;
%a(23,64,200);
%macro a(a,b,c);
Data qwe;
Do i=1 to &c;
Count= ceil(ranuni(0)*(&b-&a))+&a;
Output;
End;
Run;
%mend;
%a(23,64,200);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Count= ceil(ranuni(0)*(&b-&a+1))+(&a-1);