sas - How to get minimum and maximum value of all the columns of a table? -
how minimum , maximum value of columns of table? please note columns may both numeric, date or character. have find min , max of variables in following format: name_of_columns, minimum, maximum
here's macro asking doesn't require know variable names or type:
%macro maxmin; /* variable names */ proc contents noprint data = test.hashval out=test.contents;run; proc sql noprint; select count(*) into: cnt test.contents;quit; %let cnt = &cnt; proc sql noprint; select name into: name1 - : name&cnt test.contents;quit; /* length of variable names , results */ proc delete data = test.results; run; %let name_len = 0; %let max_len = 0; %let min_len = 0; %do = 1 %to &cnt; proc sql noprint; select max(&&name&i),min(&&name&i) into: max&i, :min&i 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 = 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;
Comments
Post a Comment