Some Good Code Habits in SAS Language Programming

Image courtesy of Stuart Miles at FreeDigitalPhotos.net

Over a period of ten years, I have seen much good code, much more bad code, and lots more of mediocre and lazy coding habits. From my experience here are some ten tips to improve your SAS coding experience.

1 ) Use options compress=yes;  to save space. This saves space by a factor of 50%. I have often been bemused by the number of times I have been approached for more data storage by analytics practitioners and their wonderful exclamations of surprise on hearing about this option.


2 ) Do not rely on the SAS Macro language excessively. Code should be easy to read and modify. Use options macrogen symbolgen; to make Macro code in logs more readable. Using the SAS Macro language excessively is a traditional swagger fail in power and advanced users.

3 ) Preferably copy and paste small parts of log in the script code itself , if you are not in the habit of saving logs. Comment out the logs/output. This is needed especially for version control of datasets, variable creation, file sizes. While copying and pasting logs and output to script/editor window can sometimes be problematic , it helps make code more understandable and much more efficient to project managers and transition managers. Version control in dataset names is critical to make the projects more streamlined.

4 ) Please comment on code. Not every human being can read SAS code like a computer. Use Ctrl + / to comment and Ctrl + Shift + / to uncomment code. Comments are statments and code between /* and */  and they are ignored upon program execution.

5 ) Use Keyboard Macros to cut down on repeated code steps like various procs.

6 ) Utilize Cross Tabs
Use –

proc freq  data=dataset ;

tables varnames*varnames2  /list nomissing ;

run ;
as a powerful way to understand cross tab as an analytical technique. It beats many other more complicated ways to look at the data.

7 ) It is best to optimize and balance Proc sql and Data step for data manipulation. While Proc SQL is quite good for existing learners of SQL and for merging datasets if they are indexed, the Data Step is a powerful way to manipulate data. Avoid using either of them exclusively to the detriment of the other.

8 ) Read updates to support.sas.com or participate on sascommunity.org as many new features are often buried deep within these websites. New methods like hash method are quite powerful.

9 ) Learn cross platform techniques like using R from within SAS, or connecting to Oracle Databases from SAS, or using SAS and JMP together. Preferably get  certified in at least one analytics certificate.

10 ) Learn how to use sub queries within proc sql efficiently including using aggregated functions within proc sql. The case expression method is a powerful and much underutilized method within proc sql.

Hope this helps your SAS coding. Do share your top practices.

Interested in a career in Data Science?
To learn more about Jigsaw’s Data Science with SAS Course – click here.
To learn more about Jigsaw’s Data Science with R Course – click here.
To learn more about Jigsaw’s Big Data Course – click here.

Related Articles

loader
Please wait while your application is being created.
Request Callback