turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Data Step vs. Proc SQL: General Comparisons

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-24-2016 03:29 PM

What can you do in a Data Step that you can't do in PROC SQL and vice versa? What are situations where you would prefer one over the other (when is it best to use PROC SQL and when is it best to use the Data Step)? Thank you in advance for your input.

Accepted Solutions

Solution

10-24-2016
05:49 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JediApprentice

10-24-2016 04:36 PM - last edited on 10-25-2016 08:07 AM by ChrisHemedinger

A simple google search (proc sql and data step comparing) gives this paper.

http://www2.sas.com/proceedings/sugi29/269-29.pdf

Also, @PGStats offers this summary:

Programming levelIn proc SQL, you describe what you want and let the procedure figure out the way to do it.

In a data step, you describe what operations must be done, in detail, to get what you want.

Data structureIn proc SQL, tables are sets (unordered). Join operations are defined in terms of the cartesian product.

In a data step, datasets are sequences of records. Merge and update operations require prior sorting.

SummariesIn proc SQL, a limited group of summary functions can accumulate information about subgroups of data.

in a data step, you can store information from one iteration to the next, but you must calculate your own summaries.

TransportabilityMost SQL queries can be moved to database servers with minor adjustments.

The data step must be run by SAS.

EfficiencyProc SQL will perform on your behalf many optimisations that are not trivial.

A data step is a compiled program that can outperform any interpreted data manipulation script such as SQL, given enough effort.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JediApprentice

10-24-2016 04:25 PM

**Programming level**

In proc SQL, you describe what you want and let the procedure figure out the way to do it.

In a data step, you describe what operations must be done, in detail, to get what you want.

**Data structure**

In proc SQL, tables are sets (unordered). Join operations are defined in terms of the cartesian product.

In a data step, datasets are sequences of records. Merge and update operations require prior sorting.

**Summaries**

In proc SQL, a limited group of summary functions can accumulate information about subgroups of data.

in a data step, you can store information from one iteration to the next, but you must calculate your own summaries.

**Transportability**

Most SQL queries can be moved to database servers with minor adjustments.

The data step must be run by SAS.

**Efficiency**

Proc SQL will perform on your behalf many optimisations that are not trivial.

A data step is a compiled program that can outperform any interpreted data manipulation script such as SQL, given enough effort.

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JediApprentice

10-24-2016 04:27 PM

Suggest you do some own research and then post your detailed answer here for us to comment.

You could start with some Internet research. Already a simple Google search like "site:support.sas.com 9.4 sql vs data step" will return results.

Solution

10-24-2016
05:49 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to JediApprentice

10-24-2016 04:36 PM - last edited on 10-25-2016 08:07 AM by ChrisHemedinger

A simple google search (proc sql and data step comparing) gives this paper.

http://www2.sas.com/proceedings/sugi29/269-29.pdf

Also, @PGStats offers this summary:

Programming levelIn proc SQL, you describe what you want and let the procedure figure out the way to do it.

In a data step, you describe what operations must be done, in detail, to get what you want.

Data structureIn proc SQL, tables are sets (unordered). Join operations are defined in terms of the cartesian product.

In a data step, datasets are sequences of records. Merge and update operations require prior sorting.

SummariesIn proc SQL, a limited group of summary functions can accumulate information about subgroups of data.

in a data step, you can store information from one iteration to the next, but you must calculate your own summaries.

TransportabilityMost SQL queries can be moved to database servers with minor adjustments.

The data step must be run by SAS.

EfficiencyProc SQL will perform on your behalf many optimisations that are not trivial.

A data step is a compiled program that can outperform any interpreted data manipulation script such as SQL, given enough effort.