This tutorial explains how to create a random sample with PROC SQL.
The RANUNI function performs random sampling and OUTOBS restricts number of rows processing.
proc sql outobs = 10; create table tt as select * from sashelp.class order by ranuni(1234); quit;
In this case, we are selecting 10 random samples.
proc sql outobs = 10;
: This line is setting an option in the SQL procedure that limits the output to only 10 observations. Theoutobs
option restricts the number of rows that will be written to the output table.create table tt as select * from sashelp.class order by ranuni(1234);
: This line is creating a new table namedtt
using theCREATE TABLE
statement. The table is being populated with the data from thesashelp.class
table, which is a built-in dataset in SAS containing information about students. Theorder by ranuni(1234)
part is sorting the data randomly based on the seed value1234
provided to theranuni
function. As a result, the rows in thett
table will be randomly ordered.quit;
: This line is used to exit the SQL procedure and complete the data manipulation.
Didnt got the logic behind the Random sampling, Can anyone please explain me?
ReplyDelete