How to apply a mathematical expression to all columns of a table in SAS?

The expression will be applied to each of the 747 columns of a table/dataset. Follow the expression: (variable-mean variable) / (maximum variable value-minimum variable value).

Will be executed in the SAS.

Author: LuizZ, 2019-08-09

2 answers

The procedure "proc standardize", called by the command PROC STDIZE, allows you to perform various forms of standardization of the numerical variables of a dataset/table in SAS. For complete documentation of the procedure, see this link .

Each of the PROC stdize methods assigns different values to the LOCAL (local) and SCALE (scale) parameters. These parameters are then combined with the original variables as per the function below (see pages 5-6 of documentation):

resultado = soma + multiplicação x (original - local)/escala

You can verify that none of the default methods of PROC STDIZE automatically perform the transformation you want. So the solution is to combine two of these procedures, MEAN: which saves the average of the columns as a local variable; and RANGE: which saves the amplitude of the columns as a scale variable (see pages 21 and 22 of the documentation). This can be done through the code:

* Salva as médias das variáveis numéricas;
proc stdize data=have method=mean out=out1 outstat=medias;
var _numeric_;
run;

* Salva a amplitude das variáveis numéricas;
proc stdize data=have method=range out=out1 outstat=amplitude;
var _numeric_;
run;

* Cria uma tabela com as médias como medida "local" e a amplitude como medidas de "escala";
data local_e_escala;
set medias (where=(_type_='LOCATION')) amplitude (where=(_type_='SCALE'));
run;

* Cria novo método de padronização utilizando a tabela criada como input; 
proc stdize data=have method=in(local_e_escala) out=want;
var _numeric_;
run;
 1
Author: LuizZ, 2020-11-09 21:53:04

Hello

In SAS there is a library called SASHELP with views that can help in various situations One of them is called VCOLUMN, where it contains the name of all the columns in each table. You can filter this view and select the variables you want to use and create a looped macro to do the calculations.

 0
Author: miazevedo, 2020-05-21 00:30:16