The script begins by standardizing the numerical variables of the SASHELP.CLASS dataset using the median as the center and the MAD (Median Absolute Deviation) as a robust scale. Then, it performs temperature conversions from Celsius to Fahrenheit and Kelvin, illustrating basic matrix operations in IML. Finally, a simple arithmetic calculation example is presented.
Data Analysis
Type : MIXTE
The script uses the SASHELP.CLASS dataset for standardization. Temperature data and variables 'x', 'y' are created directly within the IML script.
1 Code Block
PROC IML
Explanation : This block starts by defining a `SPI` library pointing to `SASUSER`. It then initializes a `PROC IML` session to read the numerical variables from the `SASHELP.CLASS` dataset. It calculates the median (`c`) and MAD (`s`) of each variable, then standardizes the data (`stdX`) and displays the calculated statistics.
Copied!
libname SPI (SASUSER); /* location of data sets */
proc iml;
/* standardize data by using robust estimates of center and scale */
use Sashelp.Class; /* open data set for reading */
read all var _NUM_ into x[colname=VarNames]; /* read variables */
close Sashelp.Class; /* close data set */
/* estimate centers and scales of each variable */
c = median(x); /* centers = medians of each column */
s = mad(x); /* scales = MAD of each column */
stdX = (x - c) / s; /* standardize the data */
print c[colname=VarNames]; /* print statistics for each column */
print s[colname=VarNames];
1
LIBNAME SPI (SASUSER); /* location of data sets */
2
3
PROC IML;
4
/* standardize data by using robust estimates of center and scale */
5
use Sashelp.Class; /* open data set for reading */
6
read all var _NUM_ into x[colname=VarNames]; /* read variables */
7
close Sashelp.Class; /* close data set */
8
9
/* estimate centers and scales of each variable */
10
c = median(x); /* centers = medians of each column */
11
s = mad(x); /* scales = MAD of each column */
12
stdX = (x - c) / s; /* standardize the data */
13
14
PRINT c[colname=VarNames]; /* print statistics for each column */
15
PRINT s[colname=VarNames];
2 Code Block
PROC IML Data
Explanation : This block creates a `Celsius` vector with several values. It then converts these temperatures to Fahrenheit and Kelvin degrees using matrix operations and displays the results.
Copied!
/* convert temperatures from Celsius to Fahrenheit scale */
Celsius = {-40, 0, 20, 37, 100}; /* some interesting temperatures */
Fahrenheit = 9/5 * Celsius + 32; /* convert to Fahrenheit scale */
print Celsius Fahrenheit;
Kelvin = Celsius + 273.15; /* convert to Kelvin scale */
print Kelvin;
1
/* convert temperatures from Celsius to Fahrenheit scale */
Explanation : This block illustrates a simple arithmetic calculation in IML: assigning values to `x` and `y`, adding them to obtain `z`, then displaying the result. The `PROC IML` session ends with the `quit` statement.
Copied!
/* Present a simple example program with comments. */
/* The PROC IML statement is not required in SAS/IML Studio programs. */
x = 3; /* 1 */ /* NUMBERS indicate steps that */
y = 2; /* are described in a list */
z = x + y; /* 2 */ /* AFTER the program. */
print z; /* display result */ /* Other statements are briefly */
/* described WITHIN the program. */
quit;
1
/* Present a simple example program with comments. */
2
/* The PROC IML statement is not required in SAS/IML Studio programs. */
3
x = 3; /* 1 *//* NUMBERS indicate steps that */
4
y = 2; /* are described in a list */
5
z = x + y; /* 2 *//* AFTER the program. */
6
7
PRINT z; /* display result *//* Other statements are briefly */
8
/* described WITHIN the program. */
9
10
QUIT;
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.
Related Documentation
Aucune documentation spécifique pour cette catégorie.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.