Use List Object in SAS: Yet Another Undocumented Feature in SAS 9.4

Last year I gave a talk in SESUG 2013 on list manipulation on SAS using a collection of function-like macros. Today I just explored in my recently upgraded SAS 9.4 that I can play with list natively, which means I can create a list, slice a list and do other list operations in Data Steps! This is not documented yet(which means it will not be supported by the software vendor) and I can see warning message in Log window like “WARNING: List object is preproduction in this release”,  and it is still limited somehow, so use it in your own risk (and of course, fun).  Adding such versatile list object will definitely make SAS programmers more powerful. I will keep watch its further development.


Some readers emailed to me that they can’t get the expected results as I did here. I think it’s best to check your own system:

I. Make sure you use the latest SAS software. I only tested on a 64-bit Window 7 machine with SAS 9.4 TS1M1:


II. Make sure all hotfixes were applied (You can use this SAS Hot Fix Analysis, Download and Deployment Tool).


*************Update End********

The followings are some quick plays and I will report more after more research:

1. Create a List

It’s easy to create a list:

data _null_;
a = ['apple', 'orange', 'banana'];
put a;

the output in Log window:


You can also transfer a string to a list:

data _null_;
a = ‘SAS94′
b =list(a)
put b;


2. Slice a List

Slicing a list is also pretty straightforward, like in R and Python:

data _null_;
a = ['apple', 'orange', 'banana'];
b = a[0];
c = a[:-1];
d = a[1:2];
put a;
put b;
put c;
put d;


3. List is Immutable in SAS!?

I felt much confortable to play list operations in SAS but a weird thing just happened. I tried to change a value in a list:

data _null_;
a = ['apple', 'orange', 'banana'];
a[0] = ‘Kivi’;
put a;

Unexpectedly, I got an error:


hhh, I need to create a new list to hold such modification? This is funny.

Based on my quick exploration, the list object in SAS is pretty intuitive from a programmers’ point of view. But since it’s undocumented and I don’t know how long it will stay in “preproduction” phase,  just be careful to implement it in your production work.

Personally I feel very exciting to “hack” such wonderful list features in SAS 9.4. If well implemented, it will easily beat R and Python (which claim themselves supporting rich data types and objects) as a scripting language for SAS programmers. I will keep update in this page.


2 Responses to “Use List Object in SAS: Yet Another Undocumented Feature in SAS 9.4”

  1. Lex Jansen
    2. April 2014 um 06:34

    Great find ;-)

  2. Anton
    2. April 2014 um 10:47

    Hi Jiangtang,

    Apparently the list macros are something every SAS programmer writes, in frustration of the lack of data structures in SAS, at some point along the career! Mine used functional programming style MAP and APPLY, so if I wanted to do something with a list, I called a macro what took as parameters a macro to be applied to an element and a sequence itself. It worked, yet I had to ditch the concept because other people working on the same code base were not headstrong enough)) They even went as low as mentioning it in their 360-degree feedback on me. Funny. I have not read your article before; it was rather invigorating, especially the striking similarities in the macro systems, superficially at least.

    So it is a great news SAS gets some elements of e.g. Python! It is 2014 after all. I wonder, is there some syntax to iterate over a sequence?

Leave a Reply