As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Coaching SAS® Beginner Programmers

From sasCommunity
Jump to: navigation, search

Title

Coaching SAS® Beginner Programmers: Common Problems and Some Solutions

Author

Peter Timusk, Centre for Special Business Projects, Statistics Canada, Ottawa, Ontario Canada

Abstract

This paper will present a number of problems SAS beginner programmers encounter when first writing SAS programs. The paper will cover three cases and show how pointing out patterns to beginner programmers will aid them in avoiding errors in their SAS code.

Online Materials

View the pdf for this SASGF2013 paper Coaching SAS® Beginner Programmers: Common Problems and Some Solutions.


Examples

Example 1: The IF statement and the order of operations of logic operators and the use of parentheses.

Example 1: the correct code:

IF ( A1=1 or A2 = 1 ) and ( B1=2 and B2=2 and B3=2 ) THEN Var1=1; ELSE Var1 =0;

Example 1: the incorrect code:

IF A1=1 or A2 = 1 and B1=2 and B2=2 and B3=2 THEN Var1=1; ELSE Var1 =0;

Example 2: The different between speaking a logic expression and how to code a logic expression with an example from setting ranges for displaying a variable’s count in five columns.

Example 2: the correct code:

IF Var1 = 0 THEN Col_1 = 1 ; ELSE Col_1 = 0 ;
IF 0 < Var1 <= 1 THEN Col_2 = 1; ELSE Col_2 = 0 ;
IF 1 < Var1 <= 2 THEN Col_3 =1; ELSE Col_3 = 0 ;
IF 2 < Var1 <= 3 THEN Col_4 = 1 ; ELSE Col_4 = 0;
IF Var1 > 3 THEN Col_5 = 1; ELSE Col_5 = 0;

Example 2: the incorrect code:

IF Var1 = 0 THEN Col_1 = 1 ; ELSE Col_1 = 0 ;
IF 0 < Var1 and <= 1 THEN Col_2 = 1; ELSE Col_2 = 0 ;
IF 1 < Var1 and <= 2 THEN Col_3 =1; ELSE Col_3 = 0 ;
IF 2 < Var1 and <= 3 THEN Col_4 = 1 ; ELSE Col_4 = 0;
IF Var1 > 3 THEN Col_5 = 1; ELSE Col_5 = 0;


Contact Info

Please check out my user page. You can also email me.