FPCASCORE Procedure

Getting Started: FPCASCORE Procedure

Note: Input data must be in a table that is accessible in your session. You can refer to this table by using a two-level name. The first level is a libref, and the second level is the table name. For more information, see the section Using SAS Viya Workbench in Chapter 2, Shared Concepts.

This example demonstrates how to use the FPCASCORE procedure to score new functional observations by using a model that is saved by the FPCA procedure. The following statements generate two simulated data sets by using the IML procedure:

proc iml;
   call randseed(233);
   N = 50;      /* Number of training curves */
   N_new = 50;  /* Number of new curves to score */
   M = 100;     /* Number of time points */
   s = do(0, 10, (10 - 0) / (M - 1));

   start meanFunct(s);
      return (s + 10 # exp(-(s - 5)##2));
   finish;
   start eigFunct1(s);
      return (cos(2 * s * constant('PI') / 10) / sqrt(5));
   finish;
   start eigFunct2(s);
      return (-sin(2 * s * constant('PI') / 10) / sqrt(5));
   finish;

   /* Simulate training data */
   Ksi_train = j(N, 2);
   call randgen(Ksi_train, "Normal");
   Ksi_train = Ksi_train * diag({5, 2});

   eig1 = eigFunct1(s);
   eig2 = eigFunct2(s);
   meanVec = meanFunct(s);
   y_train = Ksi_train * (eig1 // eig2) + meanVec;

   /* Simulate new data */
   Ksi_new = j(N_new, 2);
   call randgen(Ksi_new, "Normal");
   Ksi_new = Ksi_new * diag({5, 2});
   y_new = Ksi_new * (eig1 // eig2) + meanVec;

   s_col = s`;
   s_ytrain = s_col || y_train`;
   s_ynew = s_col || y_new`;

   ytrain_colnames = "y1":"y50";
   ynew_colnames = "y1":"y50";
   colnames_train = {"_TIMEPOINTS_"} || ytrain_colnames;
   colnames_new = {"_TIMEPOINTS_"} || ynew_colnames;

   create fpca_train_data from s_ytrain[colname=colnames_train];
   append from s_ytrain;
   close fpca_train_data;

   create fpca_new_data from s_ynew[colname=colnames_new];
   append from s_ynew;
   close fpca_new_data;
quit;

The fpca_train_data and fpca_new_data tables contain functional observations that have 100 time points. The first column contains the time points, and the remaining columns contain the observed values for each function.

To use these data sets with PROC FPCA and PROC FPCASCORE, you submit the following statements. These statements assume that your SAS library is named mylib, but you can substitute any appropriately defined SAS library.

   data mylib.fpca_train_data;
      set fpca_train_data;
   run;

   data mylib.fpca_new_data;
      set fpca_new_data;
   run;

The following PROC FPCA call trains a model on the training data and saves the model in an analytic store:

proc fpca data=mylib.fpca_train_data nbins=50;
   input y1-y50;
   output out=mylib.fpca_scores npc=2;
   savestate rstore=mylib.state_fpca;
run;

The following statements use PROC FPCASCORE to compute functional principal component scores for the new data:

proc fpcascore data=mylib.fpca_new_data model=mylib.state_fpca;
   input y1-y50;
   output out=mylib.fpca_scored_new npc=2;
run;

The mylib.fpca_scored_new output table contains the first two functional principal component scores for the new curves; the scores are based on the mean function and eigenfunctions from the saved FPCA model. These scores provide a reduced-dimension representation of the new functional observations that you can use in a downstream analysis task such as classification, anomaly detection, or visualization.

Last updated: September 23, 2026