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.
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.