Good Programming Practice – Coding Style Conventions
Overview |
---|
In order to be efficient and streamline the sharing of program code between programmers, with regulatory agencies, and with external partners or vendors, it is vital for code structure to follow standard conventions. We propose that these conventions be divided into those which should be considered as mandatory, and those which are merely suggestions to be followed as applicable. |
Mandatory Coventions |
---|
The following summarizes standard programming conventions which should be followed in the creation of SAS programs.
It is easier to read
This should also prevent lines wrapping when the code is printed out, thus making it easier to read. No more than 80 characters wide is a good guideline for this.
|
Suggested Conventions |
---|
The following summarizes additional suggested programming conventions for SAS programs.
|
Examples of Well Structured SAS Code |
---|
** Derive gender specific result **; data two; set one; attrib result length=8. label='Calculated Result' gender length=$6. label='Subject Gender' ; if sex='M' then do; gender='Male'; result=(x/ym)*100; end; else if sex='F' then do; gender='Female'; result=(x/yf)*100; end; run; ** Print listing of all female subjects **; proc print data=two(where=(sex='F')); variables patno result; run; ** Create a dummy dataset with each subject and visit **; data one; do patno=1 to 40; * cycle thru patients; do visit=1 to 3; * cycle thru visits; output; end; * cycle thru visits; end; * cycle thru patients; run; Text is available under the Creative Commons Attribution-ShareAlike License ; additional terms may apply. See Terms of use for details. |