Published on :

Sans titre

This code is also available in: Deutsch Español Français
1 Code Block
PROC HPCANDISC
Explanation :
This procedure performs a canonical discriminant analysis on the `SASHELP.FISH` dataset. The `ncan=3` option specifies to calculate the first 3 canonical variables. The `outcan` dataset is created to store the analysis results, including the canonical variable scores. The `ods exclude` statement suppresses certain ODS output tables (tstruc, bstruc, pstruc, tcoef, pcoef) to avoid cluttering the log. The `Species` variable is used as both an identification and classification variable, while `Weight`, `Length1`, `Length2`, `Length3`, `Height`, and `Width` are the metric variables used in the analysis.
Copied!
1PROC HPCANDISC DATA=sashelp.fish ncan=3 out=outcan;
2 ods exclude tstruc bstruc pstruc tcoef pcoef;
3 id Species;
4 class Species;
5 var Weight Length1 Length2 Length3 Height Width;
6RUN;
2 Code Block
PROC TEMPLATE
Explanation :
This block defines a scatter plot (`statgraph`) template named `scatter` using the `PROC TEMPLATE` procedure. This template is designed to visualize the discriminant analysis results. It configures a scatter plot where the X-axis represents the first canonical variable (`Can1`) and the Y-axis represents the second canonical variable (`Can2`). Points are grouped and colored based on the `species` variable. A legend is also added to identify the different species.
Copied!
1PROC TEMPLATE;
2 define statgraph scatter;
3 begingraph;
4 entrytitle 'Fish Measurement Data';
5 layout overlayequated / equatetype=fit
6 xaxisopts=(label='Canonical Variable 1')
7 yaxisopts=(label='Canonical Variable 2');
8 scatterplot x=Can1 y=Can2 / group=species name='fish';
9 layout gridded / autoalign=(topright);
10 discretelegend 'fish' / border=false opaque=false;
11 endlayout;
12 endlayout;
13 endgraph;
14 END;
15RUN;
3 Code Block
PROC SGRENDER
Explanation :
This procedure renders the graph previously defined by the `scatter` template. It uses data from the `outcan` dataset, which contains the canonical variable scores calculated by PROC HPCANDISC, to generate the graph. The result is a visualization of the species groups in the canonical variable space.
Copied!
1PROC SGRENDER DATA=outcan template=scatter;
2RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : SAS SAMPLE LIBRARY