The motivation for the Syndemics Lab SAS Style Guide is public deployment and open contribution to our code. SAS code is primarily used to pull aggregated data from Massachusetts Public Health Data Repository (PHD) governed by the Massachusetts Department of Public Health (DPH). It is important to note the DPH only allows use of limited packages in SAS. PHD also requires the code to only pull aggregated and suppressed data and not the row-wise data.
Following is the code audit process defined by PHD an the SAS code should foremost stick to these guidelines.
Project Phase: When the project first begins accessing PHD data.
-
In the initial stage of a new PHD project, analysts will need to submit their code for the first two times for the whole project (not for each analyst in the project) before visiting DPH or submitting an electronic run through their DPH Liaison.
- Analysts should use the dummy datasets to write the draft code they will be working on.
- Analysts will send the draft code to their DPH Liaison for review no later than 48 hours before their scheduled visit.
- If analysts are only submitting code electronically and not in person, then their liaison will review the first two code submissions that they submit.
-
The DPH Liaison will briefly review:
- The code to make sure the code is in general achieving what the researcher is intending for it to achieve and that the correct variables are being used. The DPH Liaison is not responsible for ensuring that the code is correct.
- That procedures are not being used to view datasets such as:
- Using Proc Print to view observations in a dataset that are not summary level.
- Proc SQL without a create table statement (as that will print out the resulting dataset in the output).
- Procedures that produce small cell sizes (i.e. less than 10).
Further Details can be found here PHD_Data Analysis Guidelines.
- R Packages can be incorporated in the SAS code using PROC IML.
- R version 4.2.0 is installed in the SAS environment.
- Below is the comprehensive list of the R Packages approved by DPH in their SAS environment.
R Packages in PHD SAS Environment
sas/- Where the SAS code goes.gitignore- The file used to ignore details within gitREADME.md- The base file used to describe the contents of the fileLICENSE.md- The Syndemics specific open source license
The following naming standards apply to .sas files:
- File names must contain only lowercase letters.
- Use underscores _ instead of spaces.
- Avoid numbers unless required for ordered workflows.
- Avoid special characters.
- Extension must be .sas.
# Good Examples
detox.sas
respond.sas
overdoses.sas
# Bad Examples
TableOne_before.sas
TableOne_after.sas
Each SAS program should contain three major sections:
- File Header
- Global Setup
- Logic (Data Steps / Procedures / Macros)
The file header should follow the pattern:
/******************************************************************************
* File: <filename>.sas
* Project: <project name>
* Created Date: <dd MMM yyyy>
* Author: <author name>
* -----------------------------------------------------------------------------
* Last Modified: <dd MMM yyyy>
* Modified By: <author name>
* -----------------------------------------------------------------------------
* Description:
* Brief description of purpose, inputs, outputs.
*
* Inputs:
*
*
* Outputs:
*
*
* Copyright (c) <yyyy> Syndemics Lab at Boston Medical Center
******************************************************************************/- Use 4 spaces per indentation level.
- Never use tabs.
- Align nested do blocks clearly.
PROC SQL;
CREATE TABLE ndc AS
SELECT DISTINCT NDC
FROM PHDPMP.PMP
WHERE BUP_CAT_PMP = 1;
QUIT;
- Recommended maximum: 80 characters
- Break long statements across logical boundaries.
- SAS keywords should be lowercase/uppercase consistently throughout the document.
- Dataset, macros and variable names should be snake_case.
- Use snake_case
- Names must be descriptive
- Avoid abbreviations unless standard (e.g., id, dob)
- Never use special characters
- Avoid single-letter variable names
# Good Examples
treatment
new_start_date
# Bad Examples
NED
flag_mim
Macros are the primary method of modular programming in SAS.
- Use snake_case
- Verb-based naming preferred
- File name must match the macro name if standalone.
Every macro must include documentation immediately above definition:
/******************************************************************************
* Macro: calculate_bmi
*
* Description:
* Calculates body mass index.
*
* Parameters:
* weight - numeric weight in kilograms
* height - numeric height in meters
*
* Returns:
* BMI value
******************************************************************************/-
Only one dataset created per data step.
-
Avoid deeply nested conditional logic.
-
Always explicitly define lengths when creating character variables.
-
Use retain only when necessary.
-
Drop unused variables explicitly.
-
Always specify data=
-
Explicitly define output datasets
-
Do not rely on default behavior
- Use block comments for sections.
/*===========================*/
/* MAIN MERGE */
/*===========================*/
/*
As a final series of steps:
1. APCD-Pharm, APCD-Medical, Casemix, Death, PMP, Matris,
BSAS are joined together on the cartesian coordinate of Months
(1:12), Year (2015:2023), and SPINE (Race, Sex, ID)
2. The sum of the fabricated flags is taken. If the sum is strictly
greater than zero, then the master flag is set to 1.
Zeros are deleted
4. We select distinct ID, Age Bins, Race, Year, and Month and
output the count of those detected with OUD
5. Any count that is between 1 and 10 are suppressed and set to -1,
any zeros are true zeros
*/- Use inline comments sparingly and meaningfully.
%LET ICD = (
'30550','30551','30552','30553', /* ICD9 */
'F1110','F1111','F11120','F11121',
'F11288','F1129','F1193','F1199', /* ICD10 */
'9701','96500','96501','96502',
'T40691D','T40692D','T40693D','T40694D', /* Overdose Codes */
'T40411A', 'T40411D', 'T40412A', 'T40412D',
'F1193','F1199'/* Additional RESPOND */); - Define libraries at the beginning of scripts.
- Never hard-code user-specific paths.
- Use macro variables for root directories.