Compare and Conquer SAS® Programming  

  e-Guide

 

Training Videos:

Five Habits of Highly Effective SAS Programmers

Leveraging SAS/BASE Resources

Compare and Conquer e-guide I 

Compare and Conquer e-guide II


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 ProgrammingSAS Certification exam, Technical Tips, Proc Compare and common Questions and Answers.  

 

 SAS® PROGRAMMING

TECHNIQUE 1

SAS® PROGRAMMING 

TECHNIQUE 2 

 

COMPARISON 

 

DATA Step

(Simple 1:1, 1:M Joins, Non-matching/No-By Variable Joins or Similar structure/Horizontal Join)

 

PROC SQL 

(Adding new variables, Fuzzy or Complex Joins)

 

 Paper, Example

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 

 Reference, Paper, 2


 PROC MEANS


PROC SQL 


Paper , 2


PROC MEANS

(displays results by default)


PROC SUMMARY 

(almost always used with OUTPUT OUT= to save results to dataset)

 

Reference


 PROC REPORT


PROC TABULATE 

 

Reference

 

PROC REPORT


DATA _NULL_ 

 
Paper, 2
       

 PUT()

       

INPUT() 

       

 Reference

 

WHERE


IF

 Summary Sheet, SAS Tip

  Training Video


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


Discussion 

 

 

INFILE'S MISSOVER vs. TRUNCOVER

SAS Paper


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 

13. Automation of Comparing SAS® Program File Versions Located at Different Working Areas, Sheng Zhang, Junjie Lu [Macro]

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]

Powered by Wild Apricot Membership Software