SAS Programming Best Practices

Hello guys!  Here are some best practices with SAS.

I’m documenting some of the best practices I’ve learned so far as a SAS programmer.  It’s great to learn all the basics first and utilize some best practices used by most SAS programmers.  However, using best practices goes far beyond just SAS, it also goes for any other programming language you learn.  Therefore, incorporate these methods because these techniques will get you really far in your career.

  1.  Create Readable Code

Producing readable code that your co-workers will find easy to read and understand.  There’s nothing like a code that is filled with mumble jumble and you can’t find where something started and ended.  Therefore, write code that uses proper punctuation such as ending in semi-colons and writing your variables in Camel case.

Formatting should be like this:  YES!

Data new;

set old;

Run;

proc means data=new;

var newvar;

class year;

run;

Not this: NO!

data new; set old; run;

proc means data =new;

var newvar; class year;

run;

Remember to subscribe and follow me!

2.  Basic Coding Recommendations

Make sure to comment in your code to let the next person know what you did.

Note:  Method 1 may also be helpful when developing and debugging code.

Method 1: (BEST)

Efficiency consideration: every submission of the DATA step recreates the SAS data.

/*create summary report*/

proc means data=new;

more statements here;

run;

 

Method 2:

*create summary report;

proc means data=old;

more statements here;

run;

Read more SAS Programming!

3.  Use recommended formatting for SAS Code

Do this:

Data new;

set old;

Run;

proc means data=new;

var newvar;

class year;

run;

 

Not this:

data new; set old; run;

proc means data=new;

var newvar; class year;

run;

 

4.  Use Descriptive Names

Do this:

data salaryinfo2012;

set salaryinfo2011;

newsalary=

oldsalary+increase;

run;

 

Not this:

data new;

set old;

z=x+y;

run;

 

5.  Use Undrscores or Camel Case to Create Descriptive Names

What do I mean?

Canmel Case

data salaryInfo2012;

set salaryInfo2011;

newSalary=

oldSalary+increase;

run;

 

Underscores

data salary_info2012;

set salary_info2011;

new_Salary=

old_salary+increase;

run;

 

SAS names:

  • can be 32 characters long
  • must start with a letter or underscore, continuing with numbers, letters or underscores
  • can be uppercase, lowercase or mixed case.
  • are not case sensitive.

 

Now you know some best practices in SAS, so go out there and utilize these practice to make your code be more efficient and readable.

Thank you for reading!

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s