Data d1; *fake data*;
do grp =1 to 2;
do xx = 1 to 5;
if grp = 1 then N = 20;
if grp = 2 then N = abs(x-6)*10;
do i = 1 to N;
x = xx + ranuni(0) - .5;
if grp=1 then y= 5*x/10 + ranuni(0);
if grp=2 then y= 2*x*x/10 + ranuni(0);
output;
end;
end;
end;
keep grp x y;
run;
Data pred; *pretend these are results from PLM*;
do grp =1 to 2;
do x = 1 to 5 by .5;
if grp=1 then pred = 5*x/10 + 0;
if grp=2 then pred = 2*x*x/10 + 0;
output;
end;
end;
run;
ods trace off;
Proc SQL; Select min(x) into :minx TRIMMED from d1; quit;
Proc SQL; Select max(x) into :maxx TRIMMED from d1; quit;
Proc Univariate Data=d1;
Class grp;
Var x;
Histogram x / outhistogram=histout endpoints=&minx to &maxx by .2;
run;
Proc SQL; Select max(_count_) into :maxn TRIMMED from histout; quit;
Data histout;
Set histout;
scale=1;
l = -1*(grp=1) -2*(grp=2);
h = scale*(_count_/&maxn) -1*(grp=1) -2*(grp=2);
myx = _MINPT_ + .2/2; *use a new variable name, different from x*;
run;
Data both2;
Set pred histout;
run;
Proc SGPlot Data=both2 noautolegend;
highlow x=myx high=h low=l / type=bar barwidth=0.85 nooutline group=grp;
series x=x y=pred / group=grp; /*x var in highlow and series MUST be different variables*/
refline 0;
yaxis max=6 min=-2 values=(-2 to 6 by 1) VALUESHINT /*allows min/max to differ from values list*/;
run;
quit;