BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I have a list of many numeric variables and I want to calculate for them the following statistics:

Var name

number of observations

number of observations with no missing value

number of distinct value

AVG

SUM

STD

Min

Max

Q1

Q2

Q3

Q4

P5

P95

CV

I want that each variable will have a row with the required statistics 

I want that the information will be output to want data set

Ronein_0-1713257305627.png

 

 

PROC UNIVARIATE data=class outtable=want;
VAR height weight;
RUN;

 

 

 

 

VARnamenumber_observationsnumber_observations with no missing valuenumber distinct valuesAVGMEANSTDVMAXMINQ1Q2Q3Q4P5P95CV                                                                                                

4 REPLIES 4
LinusH
Tourmaline | Level 20

I think that the OUTTABLE= will give you most of the stats OOTB that you are asking for.

SAS Help Center: OUTTABLE= Output Data Set

Data never sleeps
Ronein
Meteorite | Level 14

Thanks,

It is perfect,

However I have some questions-

1- I didnt't find calculation of number of distinct values

2- I dont understand how CV is calculated. As far as I know it is STDV/mean but I dont see that this calculation is done

 

data HAVE;
input A1-A10;
datalines;
.  223  332  138  110  145   23  293  353  458
1   54   61  196  275  171  117   72   81  141
1  170  140  400  371   72   60   20  484  138
1    6  332  493  214   43  125   55  372   30
2  236  222   76  187  126  192  334  109  546
2  260  194  277  176   96  109  184  240  261
2  253  153  300   37  156  282  293  451  299
2  121  254  297  363  132  209  257  429  295
2  152  331   27  442  103   80  393  383   94
1  178  278  159   25  180  253  333   51  225
2  128  182  415  524  112   13  186  145  131
1  236  234  255  211   80  281  135  179   11
2  215  335   66  254  196  190  363  226  379
2  232  219  474   31  139   15   56  429  298
2  218  275  171  457  146  163   18  155  129
1  235   83  239  398   99  226  389  498   18
1  199  324  258  504    2  218  295  422  287
2  161  156  198  214   58  238   19  231  548
2   42  372  420  232  112  157   79  197  166
2   83  238  492  463   68   46  386   45   81
.  267  372  296  501   96   11  288  330   74
.    2   52   81  169   63  194  161  173   54
.  181   92  272  417   94  188  180  367  342
2  248  214  422  133  193  144  318  271  479
2   83  169   30  379    5  296  320  396  597
;
proc univariate data=HAVE outtable=Table noprint;
var A1-A10;
run;
/*_NOBS_='NUMBER OF OBS with no missing value'*/
/*_NMISS_='NUMBER OF OBS with  missing value'*/
/*_SUM_='SUM of values'*/
/*_MEAN_='AVG of values'*/
/*_MEDIAN_='Median(P50) of values'*/
/*_STD_='STD of values'*/
/*_MIN_='MIN of values'*/
/*_MAX_='MAX of values'*/
/*_RANGE_'MAX-MIN'*/
/*_P1_='Percentile 1'*/
/*_P5_='Percentile 5'*/
/*_P10_='Percentile 10'*/
/*_P90_='Percentile 90'*/
/*_P95_='Percentile 95'*/
/*_P99_='Percentile 99'*/
/*_Q1_='Percentile 25'*/
/*_Q3_='Percentile 75'*/
/*_MODE_='Mode value'*/
/*_CV_='STDV/Mean'*/
PaigeMiller
Diamond | Level 26

Regarding CV, the formula is right there in the PROC UNIVARIATE documentation.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/procstat/procstat_univariate_details03.htm

 

Regarding number of unique values, this is not normally a thing you want for continuous variables, and so this count of unique values is not available from PROC UNIVARIATE.

--
Paige Miller
ballardw
Super User

What is your definition of Q4 in this case? Typically that is the MAX value. Q2 is median

I would start with something like this.

proc means data=sashelp.class mean sum std min max q1 median q3  p5 p95 cv STACKODSOUTPUT;
   var _numeric_;
ods output summary=want; run;

With Proc Means you also have a number of options related to quantile calculations

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 759 views
  • 1 like
  • 4 in conversation