/***************************************************************************************************************** SAS file name: Descriptive_Statistics.sas File location: _________________________________________________________________________________________________________________ Purpose: To Demonstrate how the different descriptive statistics in PROC MEANS and PROC UNIVARIATE are calculated using the IML language. Author: Peter Clemmensen Creation Date: 01/03/2017 This Program support the "Descriptive Statistics in SAS/IML" Example on SASnrd.com *****************************************************************************************************************/ /* Request different descriptive statistics of Height using PROC MEANS */ proc means data = sashelp.class n max min range Mean Std stderr t prt maxdec=2; var Height; run; /* Calculate the same quantities "Manually" in SAS/IML */ proc iml; use sashelp.class; /* Open dataset for reading */ read all var {Height}; /* Read variable Height into vector */ close sashelp.class; /* Close dataset */ mu0 = 60; /* Hypothesised mean */ N = nrow(Height); /* Number of observations */ min = min(Height); /* Minimum Value */ max = max(Height); /* Maximum Value */ range = max - min; /* The difference between min and max */ Mean = 1/n * sum(Height); /* Population mean value */ Std = sqrt(1/(n-1) * sum((Height - Mean)##2)); /* Standard Deviation */ Std_Err = Std / sqrt(n); /* Standard error of the mean */ t_stat = (Mean - mu0) / Std_Err; /* T statistic */ p_value = (1-cdf('t',abs(t_stat),n-1))*2; /* P value associated with t-statistic */ print N max min range Mean Std Std_Err t_stat /* Print selected descriptive statistics */ p_value; quit;