e-Guide |
|
Training Videos: |
Below is a collection of advantages and disadvantages in similar SAS® programming techniques. Often, a greater understanding of SAS® programming techniques is realized after knowing the details of why one method is better than another method. Hope you also find this blog insightful.
See also New to SAS Programming, SAS Certification exam, Technical Tips, Proc Compare and common Questions and Answers.
SAS® PROGRAMMING TECHNIQUE 1 |
SAS® PROGRAMMING TECHNIQUE 2 |
COMPARISON |
(Simple 1:1, 1:M Joins, Non-matching/No-By Variable Joins or Similar structure/Horizontal Join) |
(Adding new variables, Fuzzy or Complex Joins) |
Lookup Techniques |
Correct DATA Step Merge | Incorrect DATA Step Merge | Paper 1, 2 |
Do-Loops (Top Evaluation) |
Do-Loops (Bottom Evaluation) |
|
INFILE'S MISSOVER |
INFILE'S TRUNCOVER |
|
|
|
|
PROC MEANS (displays results by default) |
PROC SUMMARY (almost always used with OUTPUT OUT= to save results to dataset) |
|
|
|
|
|
DATA _NULL_ |
Paper, 2 |
WHERE |
|
data allab; merge a (in=a) b (in=b); by id; if a then a=1; if b then b=1; run;
data allab alla anotb aandb bnota allb; merge a (in=a) b (in=b); by id; if a or b then output allab; if a then output alla;
if a not b then output anotb; if a and b then output aandb; if b not a then output bnota; if b then output allb; run;
Topic |
|
INFILE'S MISSOVER vs. TRUNCOVER |
TRUNCOVER and MISSOVER are useful alternatives to FLOWOVER. In both, SAS does not move to the next line of input data should the INPUT statement request more data than exists on the current line. Instead, it stops, and sets the remainder of the requested variables on the line to missing. The difference between the two options is how it handles the situation of a line ending in the middle of populating a variable. MISSOVER sets that variable to missing along with the others, while TRUNCOVER “settles for what it can get” and populates the variable with the last X bytes of data that were read in from the line. There is another alternative for those who prefer more extreme preventative measures – STOPOVER. This option basically ceases execution of the DATA step upon occurrence of the “end of data on a line” condition, and trips the error flag. |
PUT() vs. INPUT() |
INPUT is typically used to convert a character value into a numeric value, but it can also be used to convert a character value into a different character value, while PUT is typically used to convert a numeric value into a character one. |
1. Yet Another Lookup Method: Updatable Indexed Data Sets, Jack Hamilton
2. Beyond IF THEN ELSE: Techniques for Conditional Execution of SAS® Code Joshua Horstman
3. Table Lookup: Techniques Beyond the Obvious, Nancy Croonen, Henri Theuwissen
4. Matching Rules: Too Loose, Too Tight, or Just Right?, Richard Cadieux, Daniel R. Bretheim
5. Exploring Popular Programming Techniques for SAS® and Microsoft® Users, Kirk Paul Lafler
6. Merge with Caution: How to Avoid Common Problems when Combining SAS® Datasets
7. Five Ways to Flip-Flop Your Data, Joshua Horstman
8. So You Think You Can Combine Data Sets? Christopher J. Bost
9. SAS Data Step Merge vs SQL Joins, Patrick Cuba Blog
10. SAS SQL Join vs Data Step Merge pt2, Patrick Cuba Blog
11. Traditional SAS Programming versus SQL
12. It’s All about the Base—Procedures, Jane Eslinger
14. %DIFF: A SAS Macro to Compare Documents in Word or ASCII Format, Michelle Xu, Jay Zhou [Macro]
15. PROC FREQ and MEANS – to Stat or not to Stat, Marge Scerbo, Mic Lajiness
16. Ways to Summarize Data Using SUM Function in SAS, Anjan Matlapudi and Daniel Knapp [Proc SQL, SUM(), Proc Summary, Proc Print, Proc Means]