Thank you @Norman21 fro the help. I managed to write the following code and it seems to work/provide the desired output. Firstly, I created an empty table with the necessary specification before the macro as follows: proc sql;
Create table Datasets.Special_Perc_&Split
(Variable char length = 23 format=$50.,
Sum_Special num length = 8 format = best12.,
Sum_positive num length = 8 format = best12.,
Percentage num length = 8 format = Percent6.2);
quit; Secondly, I wrote a macro to calculate the percentage of special values for each column in any given data set. This is then added to the table that I created above for each iteration of the loop. %macro Special(dsn);
%let lib = %upcase(%scan(&dsn,1,.));
%let dsn = %upcase(%scan(&dsn,2,.));
/* Creatign macro's for each column in the data set */
data _null_;
set sashelp.vcolumn(keep=libname memname name type
where=(libname = "&lib" AND memname = "&dsn" and type = "num")) end=eof;
call symputx('col'||strip(_n_),strip(name));
if eof then call symputx('max',strip(_n_));
run;
%do i = 1 %to &max;
proc sql noprint;
select sum(&&col&i in (-1,-2,-3,-4,-5,-6,-7)) as NegS,
sum(&&col&i not in (-1,-2,-3,-4,-5,-6,-7)) as Pos,
round(calculated NegS/(calculated NegS + calculated Pos), .01) as Perct
into :SN, :SP, :Perc
from &lib..&dsn;
quit;
data b;
Variable = "&&col&i";
Sum_Special = &sn;
Sum_positive = &sp;
Percentage = &Perc;
run;
proc append base = Datasets.Special_Perc_&split data = b force;
run;
proc sql;
drop table b;
quit;
%end;
%mend special;
%special(Datasets.Longevity_Numeric_&split); Lastly, i use a proc sql to exclude those variables that have a special value percentage of more than 90%. It may not be the best way to do it, but it got the job done.
... View more