This macro calculates the Mean Absolute Deviation, defined as the average of the absolute values of the deviations from the mean. The script uses standard procedures (MEANS, TRANSPOSE) and DATA steps to manipulate data structures. It relies on external utility macros (%ranname and %get_number_column_names) for managing variable names and temporary files.
Data Analysis
Type : EXTERNE
Data is provided via the &returns macro parameter. The script expects numerical data representing returns.
1 Code Block
MACRO DEFINITION
Explanation : Macro definition and initialization of local variables and temporary table names via an external %ranname macro. Identification of numerical columns via %get_number_column_names.
Explanation : Merging raw data with their respective means. Using an array (ARRAY) to calculate the absolute value of the difference between each observation and the mean (Abs(Value - Mean)).
Copied!
data &merged;
merge &price_t &meanData;
run;
...
data &merged(drop= &i mean);
set &merged;
array z[*] &z;
do &i= 1 to dim(z);
z[&i]= sum(z[&i], -(Mean));
z[&i]= abs(z[&i]);
end;
run;
1
DATA &merged;
2
MERGE &price_t &meanData;
3
RUN;
4
...
5
DATA &merged(drop= &i mean);
6
SET &merged;
7
array z[*] &z;
8
DO &i= 1 to dim(z);
9
z[&i]= sum(z[&i], -(Mean));
10
z[&i]= abs(z[&i]);
11
END;
12
RUN;
6 Code Block
PROC MEANS Data
Explanation : Final calculation of the Mean Absolute Deviation (MAD) on the transformed data.
Copied!
proc means data= &merged mean noprint;
output out= &outData;
run;
1
2
PROC MEANS
3
DATA= &merged mean noprint;
4
OUTPUT out= &outData;
5
RUN;
6
7 Code Block
PROC DATASETS
Explanation : Cleaning up temporary tables generated during macro execution.
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 : Copyright (c) 2015 by The Financial Risk Group, Cary, NC, USA.
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.