SAS : Random Sampling with PROC SQL

Deepanshu Bhalla 1 Comment , ,

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);

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. The outobs 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 named tt using the CREATE TABLE statement. The table is being populated with the data from the sashelp.class table, which is a built-in dataset in SAS containing information about students. The order by ranuni(1234) part is sorting the data randomly based on the seed value 1234 provided to the ranuni function. As a result, the rows in the tt table will be randomly ordered.
  • quit;: This line is used to exit the SQL procedure and complete the data manipulation.
4 ways to create a random sample in SAS
Related Posts
Spread the Word!
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 1 Response to "SAS : Random Sampling with PROC SQL"
  1. Didnt got the logic behind the Random sampling, Can anyone please explain me?

Next → ← Prev