Previous Page | Next Page

The FCMP Procedure

Example 3: Executing PROC STANDARDIZE on Each Row of a Data Set


Procedure features:

PROC FCMP functions

RUN_MACRO

RUN_SASFILE

READ_ARRAY

WRITE_ARRAY


This example shows how to execute PROC STANDARDIZE on each row of a data set.


Program

 Note about code
data numbers;
   drop i j;
   array a[5];
   do j = 1 to 5;
   do i = 1 to 5;
         a[i] = ranuni(12345) * (i+123.234);
      end;
      output;
      end;
   run;
 Note about code
%macro standardize;
%let dsname = %sysfunc(dequote(&dsname));
%let colname = %sysfunc(dequote(&colname));
proc standard data = &dsname mean = &MEAN std = &STD out=_out;
   var &colname;
run;
data &dsname;
   set_out;
run;
%mend standardize; 
 Note about code
proc fcmp outlib = sasuser.ds.functions;
   subroutine standardize(x[*], mean, std);
      outargs x;

      rc = write_array('work._TMP_', x, 'x1');
      dsname = 'work._TMP_';
         colname = 'x1';
         rc = run_macro('standardize', dsname, colname, mean, std);
      array x2[1]_temporary_;
         rc = read_array('work._TMP_', x2);
      if dim(x2) = dim(x) then do;
         do i = 1to  dim(x);
            x[i] = x2[i];
          end;
         end;
   endsub;
run;
 Note about code
options cmplib = (sasuser.ds);
data numbers2;
   set numbers;
   array a[5];
   array t[5]_temporary_;
   do i = 1 to 5;
      t[i] = a[i];
   end;
   call standardize(t, 0, 1);
   do i = 1 to 5;
      a[i] = t[i];
   end;
   output;
run;

data numbers;
       drop i j;
       array a[5];
       do j = 1 to 5;
          do i = 1 to 5;
             a[i] = ranuni(12345) * (i+123.234);
         end;
          output;
       end;
    run;
 Note about code
options nodate pageno=1 ls=80 ps=64;
proc print data=work.numbers;
run;

Output

                                 The SAS System                                1

           Obs       a1         a2         a3         a4         a5

            1      45.088    93.3237    104.908     35.152    23.5725
            2      90.552     9.7548     92.696     89.987    97.9810
            3      60.596    22.7409     19.284     50.079    58.9264
            4     106.778    49.1589     22.885     20.641    30.1756
            5      34.812    71.3746     44.248    101.808    79.3731

Previous Page | Next Page | Top of Page