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.
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.
DS2 has several advantages over traditional DATA step programming in certain cases.
Structurally, DS2 programs are built from program blocks. There are a few different types:
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.
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.
Worth watching: https://www.youtube.com/watch?v=HP7tzXHxkt0&t=0s
Worth reading: https://www.lexjansen.com/pharmasug/2019/AD/PharmaSUG-2019-AD-228.pdf
Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.
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.