Getting Started with PROC SQL in SAS: A Beginner’s Guide

Patrizia Castagno
4 min readApr 5, 2024

SQL SAS introduction

PROC SQL is a dynamic procedure that merges the functionalities of Data and PROC steps into one cohesive process. It enables users to efficiently sort, summarize, subset, join (merge), and concatenate datasets. Additionally, it facilitates the creation of new variables and the direct output of results, or the seamless creation of new tables or views, all in a single streamlined step.

Syntax:

PROC SQL;
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY

QUIT;

Important: Please remember to include the semicolon (;).

Example: Let’s consider the following tables, where we only require the Model and Type columns:

Imagen by the Author

The query is:

 PROC SQL; 
SELECT TYPE, MODEL
FROM SASHELP.CARS;
QUIT;

Let’s now see how we can write these simple queries in SAS. (If you’re unsure how to access SAS OnDemand, I’ll leave you this link that explains step by step how to do it: Introduction to SAS).

To begin, create a file titled sas_sql. Next, right-click and opt for New, followed by selecting SAS Program (F4). Assign a name of your choice; for instance, I named mine my_first_step_sql.sas

--

--

Patrizia Castagno

Physics and Data Science.Eagerly share insights and learn collaboratively in this growth-focused space.LinkedIn:www.linkedin.com/in/patrizia-castagno-diserafino