Tag: SAS

SAS Essentials

The SAS Essentials section at the Western Users of SAS Software conference was created for people who are new to SAS.  Each year this section includes three core presentations designed to give both a broad overview and, at the same time, a thorough grounding in the fundamentals of SAS. For years I have thought about […]

SAS MapReduce: A Quick Followup by DS2

(DS2 would be the king!) Years ago I made up a piece of SAS code to demonstrate the basic idea of Map-Reduce. Now this idea can be best implemented by this piece of workable program with PROC DS2 (tested in SAS 9.4 TS1M2, Win7): PROC DS2; /* create some data –*/ data input_data / overwrite […]

A Quick Look at SAS DS2 Merge

The code: data a;     input i a $ b $;     datalines;     1 a1A b1     1 a1A b1     2 a2 b2     ; run; data b;     input i a $ c $;     datalines;     1 a1C c1     2 .   c2     3 .  c3     ; run; data […]

SAS macros always have a global scope

SAS allows the programmer to declare the scope of macro variables using %LOCAL or %GLOBAL, but the macros themselves are always created in the global scope.

Say you have a macro that in another language, say Python, would be considered a function. Within the macro you want a sub-macro (i.e., sub-function) to be used only within the outer macro.


%macro outer;
%put NOTE: outer;

/* This "sub-macro" is defined within the outer macro and is
intended only for use within the outer macro. */
%macro inner(foo);
%put NOTE: inner &foo;
%mend;

%inner(1);
%inner(2);
%mend;

%outer;

/* If the "sub-macro" has a local scope, the next step would fail */
%inner(3);

/* However, it succeeds */

This can lead to conflicts if the macro %inner is defined somewhere else in the same session. One way of dealing with this is to be careful to give the inner macro a unique name like __outer_inner where the underscores in the prefix suggest a local scope, and adding outer to the macro name indicates the macro is to be used only in the outer macro.

Another option is to use the %sysmacdelete to delete the inner macro:


%macro outer;
%put NOTE: outer;

%macro inner(foo);
%put NOTE: inner &foo;
%mend;

%inner(1);
%inner(2);
/* Delete the inner macro */
%SYSMACDELETE inner;
%mend;

%outer;

/* This fails because of SYSMACDELETE */
%inner(3);

Tested with SAS 9.4M3 on Windows 7.

For more posts like this, see Heuristic Andrew.

NOTE: SAS "Inside" of Hadoop

We previously looked at SAS Grid Manager for Hadoop, which brings workload management, accelerated processing, and scheduling to a Hadoop environment. This was introduced with the m3 maintenance release of SAS v9.4. M3 also introduced support for using…

NOTE: Visual Analytics V7.3 Has Arrived

Maintenance release 15w33 of SAS v9.4 arrived in August and it included a new version of Visual Analytics – version 7.3. This new release doesn’t offer significant new features over its previous releases but I did notice that Visual Analytics Viewer’s …

Gotcha with SAS, regular expressions, and end-of-line matching

Regular expressions are essential for sophisticated text processing, and it is generally easy to transfer knowledge of Perl regular expressions to the SAS functions prxparse, prxmatch, prxposn, etc. However, use caution with the end of line character …