Robust PCA Action Set
Monitoring Operation of Four Wind Turbines
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts (SAS Viya: Machine Learning Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
The following simple example shows how to use the mwpca action to monitor the operation of four wind turbines. The data, which are simulated, are the hourly energy (in kilowatts) that each turbine produces.
The following DATA step creates the Turbines data set:
data turbines;
input time Turbine1 Turbine2 Turbine3 Turbine4;
datalines;
1 3241.250445 4079.490559 3505.854227 3392.565663
2 2395.881828 3410.130913 2783.411447 2694.114311
3 3628.878452 4543.677282 3818.729737 3701.380754
4 2823.608204 3806.751908 3221.480613 3029.188791
5 3743.196614 4632.571843 3859.732421 3817.242149
6 1807.899427 2536.174173 1698.306145 1619.159414
7 2240.006055 3271.723656 2477.616826 2210.066151
... more lines ...
The following statements plot the amount of energy that each turbine produces over time, and Output 35.1.1 shows the resulting plot.
proc sgplot data=turbines;
series x=time y=Turbine1/legendlabel="Turbine1" lineattrs=(thickness=0.1);
series x=time y=Turbine2/legendlabel="Turbine2" lineattrs=(thickness=0.1);
series x=time y=Turbine3/legendlabel="Turbine3" lineattrs=(thickness=0.1);
series x=time y=Turbine4/legendlabel="Turbine4" lineattrs=(thickness=0.1);
yaxis label="Turbine";
run;
Output 35.1.1: Energy Generated (in Kilowatts)

You can load the Turbines data set into your CAS session by specifying your CAS engine libref in the following DATA step. These statements assumes your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.turbines;
set turbines;
run;
The following statements run the mwpca action:
ods trace on;
proc cas;
loadactionset "robustPca";
action mwpca /
table={name="turbines"}
windowsize=200
stepsize=1
id="time"
output={casout={name="windowpcs" replace=True} standardPc=True}
;
run;
Note that in the output statement standardpc is specified to true. Using this option is recommended.
Output 35.1.2 displays the "Model Information," "Dimensions," and "Results Summary" results tables. In the "Model Information" table, you can see the windowsize and stepsize parameters and some other parameters that are set to their default values. A window size of 200 and step size of 1 indicates that the procedure starts with the first 200 observations in the data table, calculates the principal components, moves ahead one observation and uses observations 2–201 to calculate the principal components, and continues in this manner until the entire data table has been used.
In the "Dimensions" table, you can see the number of observations and variables in the input table. The mwpca action ignores observations that have missing values; however, the ID column cannot be missing for any observation.
In the "Results Summary" table, you can see that the windowpcs data table contains 701 windows, each of which has 200 observations. You can also see that the solution status is optimal; that is, the algorithm ended successfully for all windows.
Output 35.1.2: Results Tables
| Model Information | |
|---|---|
| Data Source | TURBINES |
| Window Size | 200 |
| Step Size | 1 |
| SVD Method | Eigenvalue Decomposition |
| Cumulative Eigenvalue Percent Tolerance | 1 |
| Number of Observations | 900 |
|---|---|
| Number of Variables | 4 |
| Results Summary | |
|---|---|
| Number of Windows | 701 |
| Solution Status | Optimal |
| Run Time (Seconds) | 1.01 |
You can see the output table windowpcs in your CAS engine library (mycas). This table contains the first principal component for each turbine and information about how it changes over time. The following statements plot the value of the first principal component over time for each turbine. Output 35.1.3 shows the resulting plot.
data windowpcs;
set mycas.windowpcs;
run;
proc sgplot data =mycas.windowpcs;
series x= window_id y= Turbine1/legendlabel = "Turbine1" lineattrs = (thickness = 1);
series x= window_id y= Turbine2/legendlabel = "Turbine2" lineattrs = (thickness = 1);
series x= window_id y= Turbine3/legendlabel = "Turbine3" lineattrs = (thickness = 1);
series x= window_id y= Turbine4/legendlabel = "Turbine4" lineattrs = (thickness = 1);
yaxis label="First Principal Component";
xaxis label="Window";
run;
As you can see in Output 35.1.3, the first principal component displays the same pattern of changes for the first three turbines. However, toward the end, the first principal component for the fourth turbine starts to behave differently from the other three turbines, indicating an abnormality in the operation of the fourth turbine.
Output 35.1.3: First Principal Component

Monitoring Operation of Four Wind Turbines
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the turbines data to the comma-separated-value (CSV) file turbines.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="turbines.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
s:loadactionset{actionset="robustPca"}
s:mwpca{
table={name="turbines"},
windowsize=200,
stepsize=1,
id="time",
onrpca=1,
output={casout={name="windowpcs", replace=True}, standardPc=True}
}
Monitoring Operation of Four Wind Turbines
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the turbines data to the comma-separated-value (CSV) file turbines.csv and then use the following code to load the CSV file into CAS:
s.upload_file('turbines.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
s.loadactionset(actionset="robustPca")
s.mwpca(
table={"name" : "turbines"},
windowsize=200,
stepsize=1,
id="time",
onrpca=1,
output={"casout":{"name":"windowpcs", "replace":True}, "standardPc":True}
)
Monitoring Operation of Four Wind Turbines
This section contains R code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be loaded into CAS. One way to do this is to convert the turbines data to the comma-separated-value (CSV) file turbines.csv and then use the following code to load the CSV file into CAS:
data <- cas.read.csv(s,
"turbines.csv",
header=TRUE,
casOut=list(name="turbines",replace=TRUE))
loadActionSet(s,'robustPca')
rs <- cas.robustPca.mwpca(s,
table =list(name="turbines"),
windowsize=200,
stepsize =1,
id ="time",
output =list(casout=list(name="windowpcs",replace=TRUE),
standardPc=TRUE))