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.
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.
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.
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.