SAS-Efficient Programming Techniques:

Efficient SAS Programming Techniques:

Efficiency and performance strategies can be classified into five areas as follows:
1. CPU Time
2. Data Storage
3. Elapsed Time
4. I/O
5. Memory
Quick Tips:

  • Use System Options such as BUFNO=, BUFOBS=, BUFSIZE= COMPRESS=, etc.
  • Use DATA Step Options such as NOMISS or NOSTMTID.
  • Use the LENGTH Statement to reduce the size of numeric variables and storage space.
  • Use numeric variables for analysis, otherwise create character variables - less CPU intensive.
  • Use the KEEP or DROP statements to control only variables desired.
  • Delete Unwanted Datasets in the WORK area.
  • Combine Steps to minimize the number of DATA and/or PROC steps.
  • Use Data Compression.
  • Conserve on Memory (e.g., turning off NOMACRO, array processing)
  • Use Formats and Informats to save CPU during complex logic assignments.
  • Avoid unnecessary sorting with PROC SORT.
  • Control sorting by combining two or more variables at a time when sorting is necessary.
  • Use Subsetting IF statements to subset datasets.
  • Use WHERE statements to subset datasets.
  • Use indexes to optimize the retrieval of data.
  • Construct IF-THEN/ELSE statements to process condition(s) with greatest frequency first.
  • Save intermediate files in multi-step applications.
  • Use PROC APPEND versus SET statement to concatenate datasets.
  • Use PROC SQL to consolidate multiple operations into one step.
  • Use the PROC SQL Pass-Through Facility to pass logic to target database for processing.
  • Use the Stored Program Facility to store SAS DATA steps in a compiled format.
  • Use DATA Views and SQL Views to create "virtual" tables.
  • Use SAS Functions to perform common tasks.
  • Use the DATASETS Procedure COPY statement to copy datasets with built-in indexes.
  • Use the DATA _NULL_ step to avoid creating a dataset when one is not needed but processing is.
  • Use a CLASS statement in procedures that support it to avoid having to sort data.




1. CPU Time
1) Use KEEP or DROP statements to retain desired variables.
2) Create and use indexes with large datasets.
3) Utilize macros for redundant code.
4) Use IF-THEN/ELSE statements to process data.
5) Use the DATASETS procedure COPY statement to copy datasets with indexes.
6) Use the SQL procedure to consolidate the number of steps.
7) Turn off the Macro facility when not needed.
8) Avoid unnecessary sorting - plan its use.
9) Use CLASS statements in procedures.
10) Use the Stored Program Facility for complex DATA steps.


2. Data Storage
1) Use KEEP or DROP statements to retain desired variables.
2) Use LENGTH statements to reduce variable size.
3) Use data compression strategies.
4) Create character variables as much as possible.
5) Use DATA _NULL_ steps for processing null datasets.


3. I/O
1) Read only data that is needed.
2) Use WHERE statements to subset data.
3) Use data compression for large datasets.
4) Use the DATASETS procedure COPY statement to copy datasets with indexes.
5) Use the SQL procedure to consolidate code.
6) Store data in SAS datasets, not external files.
7) Perform data subsets early and at same time.
8) Use KEEP or DROP statements to retain desired variables.


4. Memory
1) Read only data that is needed.
2) Use WHERE conditions when possible.
3) Use the DATASETS procedure COPY statement to copy datasets with indexes.


5. Programming Time
1) Use the SQL procedure for code simplification.
2) Use procedures whenever possible.
3) Document programs and routines with comments.
4) Utilize macros for redundant code.
5) Code for unknown data values.
6) Assign descriptive and meaningful variable names.
7) Store formats and labels with the SAS datasets that
use them.
8) Test program code using "complete" test data.

Blog Widget by LinkWithin

Search this blog..

Loading