Tuesday, December 3, 2013

SAS: Temporary arrays

Spent way too much time last night trying to determine why a program was taking too long to run.  The time to run increased exponentially -- rather than linearly -- as more records were processed.  I determined that it was too much reliance on symget and symput.  When I used a temporary array instead, the program ran very quickly.

The following statement will create an array of numeric variables. Key points with temporary arrays:
  • You must specify the size with a numeric constant (or, as I did here, with a macro variable which evaluates to a numeric constant.)
  • Temporary arrays are automatically retained.
  • Temporary arrays are not written to the output data set.

Note how I was able to initialize all entries to zero.

      array used [&_NVARS] _temporary_ (&_NVARS * 0);


Here I check the value of an element in the array:

      if (used[&i] = 0) then do;

Here I set the value of an element in the array:

      used[save_i] = 1;







No comments:

Post a Comment