Question: How to get minimum and maximum value of all the columns of a table? Please note that the columns may be both numeric, date or character. We have to find min and max of all the variables in following format:
Name\_of\_columns, minimum, maximum

Answer: 
Here's a macro that will do what your asking for which doesn't require you to know the variable names or their type:

```
%macro maxmin;
/* get variable names */
proc contents noprint data = test.hashval out=test.contents;run;

proc sql noprint;
select count(*) into: cnt from test.contents;quit;

%let cnt = &cnt;

proc sql noprint;
select name into: name1 - : name&cnt from test.contents;quit;

/* get length of all variable names and results */
proc delete data = test.results; run;
%let name_len = 0;
%let max_len = 0;
%let min_len = 0;

%do i = 1 %to &cnt;
    proc sql noprint;
         select max(&&name&i),min(&&name&i) into: max&i, :min&i from test.hashval;quit;

    %let max&i = %cmpres(&&max&i);
    %let min&i = %cmpres(&&min&i);

    %if (&name_len < %length(&&name&i)) %then %let name_len = %length(&&name&i);
    %if (&max_len < %length(&&max&i)) %then %let max_len = %length(&&max&i);
    %if (&min_len < %length(&&min&i)) %then %let min_len = %length(&&min&i);

%end;

/*create results */
%do i = 1 %to &cnt;

   data temp;
   length NAME $&name_len MAX $&max_len MIN $&min_len;
   NAME = "&&name&i";
   MAX = "&&max&i";
   MIN = "&&min&i";
   run;

   proc append base = test.results data= temp force;run; 

%end;
%mend maxmin;
%maxmin;

```
```
proc sql;
    create view myExtrema_1 as 
    Select min(alphaVar) as alphaVar, ..., put(min(numVar),best32.) as numVar, ...
    from myTable
    Union
    Select max(alphaVar), ..., put(max(numVar),best32.), ...
    from myTable;
quit;
proc transpose data=myExtrema_1
    out=myExtrema(rename=(
        _name_ = Variable
        col1 = Minimum
        col2 = Maximum
    ));
    var alphaVar ... numVar ...;
run;

```

On request of the commenter, I tested it with

```
proc sql;
    create view Class_1 as 
    Select min(Name) as Name
         , min(Sex) as Sex
         , put(min(Age),best32.) as Age
         , put(min(Height),best32.) as Height
         , put(min(Weight),best32.) as Weight
    from sasHelp.Class
    Union
    Select max(Name) as Name
         , max(Sex) as Sex
         , put(max(Age),best32.) as Age
         , put(max(Height),best32.) as Height
         , put(max(Weight),best32.) as Weight
    from sasHelp.Class;
quit;
proc transpose data=Class_1
    out=Class(rename=(
        _name_ = Variable
        col1 = Minimum
        col2 = Maximum
    ));
    var Name Sex Age Height Weight;
run;

```