BookmarkSubscribeRSS Feed

Beyond the DATA Step: An Introduction to DS2

Started ‎07-21-2026 by
Modified ‎07-21-2026 by
Views 213

If you've spent any time writing SAS code, you already know the DATA step: the workhorse that reads, transforms, and outputs data in nearly every SAS program. But there's a lesser-known language sitting right alongside it that unlocks a whole new set of functionality. It's called DS2. In this article, I’ll discuss what it is, why it exists, what it's used for, and how to get started.

What is DS2?

DS2 is a proprietary SAS programming language that is appropriate for advanced data manipulation. You submit DS2 code through the DS2 procedure (PROC DS2), and depending on your environment, you can also run it in a SAS Cloud Analytic Services (CAS) server, or push it directly into a database via FedSQL. DS2 is also supported in SAS Event Stream Processing, SAS Intelligent Decisioning, and SAS Model Manager.

When should I use DS2?

DS2 has several advantages over traditional DATA step programming in certain cases.

 

  • Precision: DS2 supports ANSI data types, meaning that if you need the precision those additional data types offer, DS2 is a good choice.
  • Reusability: DS2 enables you to develop and share reusable packages of code, which can be used to reduce development time in other projects.
  • Speed: DS2 supports threaded processing on the SAS Compute server, allowing you to speed up CPU-bound programs.

Getting started with DS2

Structurally, DS2 programs are built from program blocks. There are a few different types:

 

  • DATA: Used to manipulate data and create reports
  • PACKAGE: Stores user-defined defined methods to reuse in other program blocks
  • THREAD: Stores processing instructions

A method is a subblock of a data program, package, or thread program, and it is a named block of executable code. The method definition begins with a METHOD statement and ends with an END statement. All executable statements in the DS2 program must be part of a method definition. Every DS2 program automatically includes three "system methods" (INIT, RUN, and TERM) that control setup, row-by-row execution, and cleanup, even if you never write them explicitly.

 

For example, this simple DS2 program prints the message “Hello, world” to the log:

 

proc ds2;
data _null_;
   method init();
	 dcl varchar(16) Text;
      Text='Hello, World!';
      put Text=;
   end;
enddata;
run;
quit;

 

This program contains one INIT method, which assigns a value to a variable, and then prints that variable to the log. Notice that METHOD definition ends with an END statement, the DATA block ends with an ENDDATA statement, and the PROC DS2 step ends with a RUN statement and a QUIT statement. PROC DS2 uses RUN-group processing. A RUN-group consists of one or more DS2 action statements followed by a RUN statement. Within a PROC DS2 step, you can submit more than one RUN-group without restarting the procedure. The QUIT statement indicates that we are done submitting DS2 code.

Conclusion

DS2 isn't a replacement for the DATA step, but it's a useful additional to your SAS skillset for when you need more precision, speed, or reusability than traditional SAS code can offer. With ANSI data types, threaded processing, and reusable code packages, DS2 gives you options that aren't available elsewhere in the SAS language. Stay tuned for future articles, where I’ll explore the differences between traditional DATA step code and DS2!

 

 

Find more articles from SAS Global Enablement and Learning here.

Comments
Contributors
Version history
Last update:
‎07-21-2026 09:19 AM
Updated by:

Viya Copilot Motion Graphic.gifViya Copilot Motion Graphic

Ready to see what SAS Viya Copilot can do?

Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.

Get Started →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags