I've been a busy Jedi the last few months and have spent the bulk of my non-teaching days learning new Jedi SAS tricks to share with you. The finishing touches are going on to our brand-new, one and a half day DS2 Programming: Essentials class. It's rolling out on December 16 at SAS world headquarters in Cary, NC - and I'm very much looking forward to teaching it!
DS2 is a new SAS programming language available in SAS9.4. It combines the best of the SAS DATA step and SQL:1999 programming languages. DS2 allows native manipulation of most ANSI data types (including the high-precision DECIMAL type - see "Jedi SAS Tricks: Finding Tattoine with DS2") and makes writing DATA steps for parallel processing so easy you'll be leveraging all your CPUs to get your job finished in no time. Besides all of the cool new technology, DS2 delivers some DATA step features that have been on my wish list for quite some time. One of my favorites is how DS2 leverages the LIKE expression.
As you may remember, the LIKE expression allows searching for patterns in text. You can use ''wildcards" to specify the pattern - a percent sign (%) for zero or more characters or an underscore (_) for exactly one character. Up until now, LIKE has only worked in SQL WHERE clauses and SAS WHERE statements. Wouldn't it be awesome to be able to use LIKE expressions in other SAS statements? Well with DS2, you can! For example:
libname test "!SASROOT\core\sashelp"; proc ds2; data convertibles (overwrite=yes) S_type(overwrite=yes); Keep Make Model type; method run(); set test.cars; if Model like '%convertible%' then output convertibles; if Model like '% S' then output S_type; end; enddata; run; quit; proc FedSQL number; title 'Convertible Cars'; select * from convertibles order by Make, Model, Type ; title 'S Model cars'; select * from s_type order by Make, Model, Type ; quit; |
Partial output:
I really like LIKE - and DS2! How about you? If so, I hope I'll see you in a DS2 class sometime soon.
Until next time, may the SAS be with you!
Mark
2 Comments
Hi, I'm a bit new to SAS and trying to learn DS2, and that's why I came across your blog. I believe that DS2 will make our code nicer and the processing time shorter for our data base. But I wanted to let you my code to do the same as you using SAS:
libname test "!SASROOT\core\sashelp";
data convertibles2 s_type2;
keep make model type;
set test.cars;
if index(model, "convertible") ge 1 then output convertibles2;
if scan(model, -1) = 'S' then output s_type2;
run;
You can accomplish this this task using functions in DS2 as well, for example:
libname test "!SASROOT\core\sashelp";
However, you cannot use the LIKE operator in a traditional base SAS DATA step.