DATA Step, Macro, Functions and more

Data Step vs. Proc SQL: General Comparisons

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 123
Accepted Solution

Data Step vs. Proc SQL: General Comparisons

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
Super Contributor
Posts: 271

Re: Data Step vs. Proc SQL: General Comparisons

[ Edited ]
Posted in reply to JediApprentice

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 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.



 

View solution in original post


All Replies
Respected Advisor
Posts: 4,920

Re: Data Step vs. Proc SQL: General Comparisons

Posted in reply to JediApprentice

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
Respected Advisor
Posts: 4,173

Re: Data Step vs. Proc SQL: General Comparisons

Posted in reply to JediApprentice

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
Super Contributor
Posts: 271

Re: Data Step vs. Proc SQL: General Comparisons

[ Edited ]
Posted in reply to JediApprentice

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 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.



 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1030 views
  • 3 likes
  • 4 in conversation