2 min read

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 = yes;
dcl double d;
method init();
   dcl int i;
   do i = 1 to 10000000;
      /
– create some money values –*/
      d = round( (ranuni(123) * 10 ), .01 );
      output;
   end;
end;
enddata;
run;

/– count the rows in multiple threads –/
thread map / overwrite = yes;
dcl double c s;
keep c s;
method run();
   set input_data;
   /– the more compuation here, the more benefit –/
   c + 1;
   s + d;
end;
method term();
   output;
   put s= c=;
end;
endthread;
run;

/– blend the results into one total –/
data reduce / overwrite = yes;
dcl thread map m;
dcl double totc tots;
keep totc tots;
method run();
   set from m threads=4;
   totc + c;
   tots + s;
end;
method term();
   output;
end;
enddata;
run;
quit;

proc print data=reduce; run;

Notice the option of “threads=4”. You can specify the thread as any number you want (the number of slaves..).

Thanks Robert Ray of SAS Institute to kindly allow me to post his code.