Contributor
Posts: 23

# Building clusters using distribution percentiles

[ Edited ]

Hi all,

I computed the variables distribution percentiles by using the following macro:

```%MACRO PERCENTILES(K);

PROC UNIVARIATE DATA = lib.c NOPRINT;
VAR var1 var2 var3
OUTPUT OUT = lib.PERCENTILES_&K.
PCTLPTS = &K. /* k-th quartile */
PCTLPRE = var1 var2 var3
PCTLNAME = _P&K.;
RUN;

%MEND;```

Now, I would like to construct a set of dummy variables for each continuous variables assuming value equal to 1 if the correspondent value of the continuous variable drops in the quantiles range and 0 otherwise.

For istance, let's assume the var1 has the first percentile equal to 0.0124; the first dummy variable relative to var1 will have value equal to 1 if var1 is less or equal to 0.0124 and 0 otherwise.

Can someone of you suggest how I can get such dummy variables?

Any hint will be appreciated.

PROC Star
Posts: 2,370

## Re: Building clusters using distribution percentiles

Like this?

``````data HAVE;
do VAR1= 1 to 1e3;
VAR2=ranuni(0);
VAR3=ranuni(0);
output;
end;
run;

%macro percentiles(k);

proc univariate data = HAVE noprint;
var VAR1 VAR2 VAR3 ;
output out      = PERCENTILES
pctlpts  = %do i=1 %to 100;&i %end;
pctlpre  = VAR1_ VAR2_ VAR3_;
run;

data WANT;
set HAVE;
if _N_=1 then set PERCENTILES;
%do i=0 %to 99;
if %if &i=0 %then .; %else VAR1_&i; < VAR1 <=VAR1_%eval(&i+1) then VAR1_IN_PCT&i =1;
if %if &i=0 %then .; %else VAR2_&i; < VAR2 <=VAR2_%eval(&i+1) then VAR2_IN_PCT&i =1;
if %if &i=0 %then .; %else VAR3_&i; < VAR3 <=VAR3_%eval(&i+1) then VAR3_IN_PCT&i =1;
%end;
drop VAR1_1--VAR3_100;
run;

%mend;

%percentiles;``````
Discussion stats