/*******************************************************************************/ /****************** sas macro npc ranking for ordered variabl
/*******************************************************************************/
/****************** SAS MACRO NPC Ranking for ordered variables
*******************/
/*******************************************************************************/
/* SINTAX: %macro graduatoria (dataset,cod,w,k,m,t,list);
LIST OF MACRO PARAMETERS:
dataset = SAS dataset’s name;
cod = name of variable identifing statistical units;
w = list of weights for the variables (weights must sum to the number
k of variables);
k = number of ordered variables;
m = number of ordered variables’ values representing ordered discrete
scores, , with the value 1 corresponding to lower
satisfaction, m to higher satisfaction ;
t = number of last values from corresponding to satisfaction’s
judgements
u = relative frequency (expressed by % without decimals, e.g. 60) of
subjects with value m in the extreme satisfactory profile
l = relative frequency (expressed by % without decimals, e.g. 70) of
subjects with value 1 in the extreme satisfactory profile
list = list of names of ordered variables.
MACRO OUTPUT:
The macro generates the SAS temporary dataset named Fisher containing
the variable ‘y_def’ representing the combined -index varying
from 0 to 1.
Example:
%graduatoria(dataset=elab,cod=matricola,w=1
1,k=2,m=4,t=2,u=60,l=70,list=v1 v2);
*******************************************************************************/
%macro graduatoria(dataset,cod,w,k,m,t,u,l,list);
proc freq noprint;
%do i=1 %to &k;
tables %scan(&list,&i) /out=freq&i;
%end;
run;
%do i=1 %to &k;
proc sort data=&dataset;
by %scan(&list,&i);
run;
proc sort data=freq&i;
by %scan(&list,&i);
run;
data f&i(drop=count percent);
merge &dataset freq&i;
by %scan(&list,&i);
freq&i=percent/100;
run;
proc sort;
by &cod;
run;
%end;
data f_tot;
merge %do i=1 %to &k; f&i %end;;
by &cod;
run;
data lambda;
set f_tot;
h=&m-&t;
array x(&k) &list;
array f(&k) %do i=1 %to &k;freq&i %end;;
array new(&k) z1-z&k;
do i=1 to &k;
if x(i)<=h then
new(i)=((1-f(i))*0.5)+x(i);
else new(i)=(f(i)*0.5)+x(i);
end;
array neww(&k) l1-l&k;
do i=1 to &k;
neww(i)=(new(i)-(1+0.5*(1-(&l/100)))+0.5)/((&m+0.5*(&u/100))-(1+0.5*(1-(&l/100)))+1);
end;
run;
data fisher;
set lambda;
array provv(&k) l1-l&k;
%do i=1 %to &k;
ww&i=%scan(&w,&i);
w&i=ww&i/&k;
%end;
array neww(&k) b1-b&k;
array minim(&k) min1-min&k;
array maxim(&k) max1-max&k;
array pesi(&k) w1-w&k;
do i=1 to &k;
neww(i)=-pesi(i)*log(1-provv(i));
minim(i)=-pesi(i)*log(1-(0.5/((&m+0.5*(&u/100))-(1+0.5*(1-(&l/100)))+1)));
maxim(i)=-pesi(i)*log(1-(((&m+0.5*(&u/100))-(1+0.5*(1-(&l/100)))+0.5)/((&m+0.5*(&u/100))-(1+0.5*(1-(&l/100)))+1)));
end;
y=%do i=1 %to %eval(&k-1); b&i+ %end; b&k;
ymin=%do i=1 %to %eval(&k-1); min&i+ %end; min&k;
ymax=%do i=1 %to %eval(&k-1); max&i+ %end; max&k;
y_def=(y-ymin)/(ymax-ymin);
run;
%mend;