Creating Dataset using Proc SQL - WHY ? | HOW ?

With PROC SQL we can not only report data in Result window but we can also create New dataset for the result we get out of Select Query

WHY? - This is needed sometime because we want to reutilize the result of Select Query in some other places for analysis, so we required to store result somewhere in dataset.

HOW? - To perform this task we just need to write Create Table <Library.dataset Name> as Before any Select Statement 

Syntax - 

PROC SQL;
CREATE TABLE <Library.dataset name> AS
SELECT variable(s)
FROM Table Name
<WHERE Conditional statement
GROUP BY Variable(s)
ORDER BY variable(s)>;
QUIT; 

See Example - 

/* Creating Dataset using proc SQL */
Proc SQL;
Create Table WORK.AUDI as Select * From SASHELP.CARS
where Make = 'Audi';
Run;

Creating Dataset using PROC SQL



 

Use of INOBS option - Fix the number of rows in newly created dataset.

If you want to limit the number of observation(rows) in dataset produced by Proc SQL then INOBS option can be used - 

See Example - 

/* Create a dataset Contains top 10 Cheapest Audi */
Proc SQL INOBS=10;
Create Table Audi as Select * From SASHELP.CARS
where Make = 'Audi'
ORDER BY MSRP;
Run;

Top 10 Cheapest Audi

 

Post a Comment

0 Comments