Triad sou.

SAS IMLで関数を自作

実用性があるのか分からない機能を紹介?


progs.sas

dm 'log; clear; output; clear';
proc datasets kill; run;
option linesize = 130 pagesize = 500;

%let execpath = " ";
%let Path = " ";
%macro setexecpath;
  %let execpath = %sysfunc(getoption(sysin));
  %if %length(&execpath) = 0 %then
    %let execpath = %sysget(sas_execfilepath);
  data _null_;
    do i = length("&execpath") to 1 by -1;
      if substr("&execpath", i, 1) = "\" then do;
        call symput("Path", substr("&execpath", 1, i));
        stop;
      end;
    end;
  run;
%mend setexecpath;
%setexecpath;

proc iml;

  /* include function */
  %include "&Path.func.sas";

  a = {
    1 2 3,
    4 5 5,
    8 3 2
  };
  b = {
    3 4 1,
    7 5 2,
    4 7 6
  };
  x = fsum(a, b);
  print "a + b = " x;
quit;

func.sas

  start fsum(a, b);

  if ncol(a) ^= ncol(b) then do;
    print "Column of a not equal column of b: " a b; stop;
  end;
  if nrow(a) ^= nrow(b) then do;
    print "Row of a not equal Row of b: " a b; stop;
  end;

  outX = a + b;
  return(outX);

  finish;
  store module = fsum;

しかしながら、SAS Customer Support Centerで公開されているIML関数は少ない。
時々使うけど、行列演算がらみの関数は他の解析パッケージに負けてるような・・・