LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 1996, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Oct 1996 08:47:28 EDT
Reply-To:     Donald Peterson-1 <Donald_Peterson-1@SBPHRD.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Donald Peterson-1 <Donald_Peterson-1@SBPHRD.COM>
Subject:      SAS/GRAPH - Jittering

Mike Zdeb wrote on (Oct-1-1996):

Does anyone have SAS code that examines a dataset and does JITTERING, i.e. making adjustments to data so plotted data points are randomly scattered about their true location if they all would have just plotted at same x-y location. There's a paper in the lastest SUGI proceedings, but I'm a lazy (andd baad) typist. Thanks. -- *Mike Zdeb NYS Department of Health (Family Health) *ESP Tower (RM 890) msz03@health.state.ny.us *Albany, NY 12237-0657 (518)474-2079

******************************************************************************** ************************************** Mike,

Here is the SAS code for Jittering graphs. Hope you will find my macro codes useful.

-Don Peterson, (Progressive Software Computing Inc - Consultant-)

%**************************************************************************** %* %* Macro: GRJITTR.SAS %* %* Author: D.Peterson & Tremmel %* %* Date: June 1994 %* %* Purpose: Jitter points in x or y direction to resolve overlap before %* plotting %****************************************************************************;

%MACRO GRJITTR(data=, group=, x=x, y=y, shiftx=, shifty=, xjitter=xjitter, yjitter=yjitter, options=);

%LOCAL sx sy mname; %let mname=GRJITTR VERS. 1.1;

%let options=%upcase(&options);

* --------- Get ranges of the axes and set jitter parameters ---------;

proc means data=&DATA; var &x &y; output out=z_zz min=xmin ymin max=xmax ymax; TITLE7 "MACRO &MNAME: Descr. stats for &x and &y"; RUN; TITLE7; run;

data _null_; set z_zz; file print; put // "Macro JITTER: The shift parameters have the following values:";

if compress("&shiftx")="" then do; sx=(xmax-xmin+1)/200; put sx= "(set to the default, which is the xrange divided by 200)"; end; else do; sx=&shiftx+0; put sx=; end; call symput('sx', compress(sx));

if compress("&shifty")="" then do; sy=(ymax-ymin+1)/150; put sy= "(set to the default, which is the yrange divided by 150)"; end; else do; sy=&shifty+0; put sy=; end; call symput('sy', compress(sy)); run;

%* --------- Generate two new items &xjitter and &yitter to contain the transformed parameters ---------;

proc sort data=&DATA; by &group &x &y;

data &DATA(drop=z_count) z_check; set &DATA end=end; by &group &x &y; file print; retain z_miscnt 0; retain z_count 0;

&xjitter=&x; &yjitter=&y;

if first.&y then z_count=0;

if not(first.&y) then do; z_count=z_count+1;

* - - - - - jitter only if x AND y are nonmissing - - - - - -;

if &y ne . and &x ne . then do;

%IF %INDEX(&OPTIONS, YTOWER) %THEN %DO; &yjitter=&y+z_count*&sy; %END; %ELSE %IF %INDEX(&OPTIONS, XTOWER) %THEN %DO; &xjitter=&x+z_count*&sx; %END; %ELSE %DO; &xjitter=&x+ranuni(700297)*&sx; &yjitter=&y+ranuni(700297)*&sy; %END;

OUTPUT Z_CHECK; end; else z_miscnt=z_miscnt+1;

end; * if not first.y;

OUTPUT &DATA;

if end then do; put "Macro &mname:" z_miscnt " overlapping data points not jittered"; put " because &x or &y is missing"; end;

label &xjitter="Jittered x" &yjitter="Jittered y"; drop z_count z_miscnt;

run;

proc sort data=z_check; by &group &x &y; run;

proc print data=z_check label; title6 "Macro &mname:"; title7 "Points that have been jittered due to complete overlap."; var &group &x &y &xjitter &yjitter; run; title6; title7; run;

proc datasets nolist; delete z_check z_zz; quit; run;

%MEND GRJITTR;


Back to: Top of message | Previous page | Main SAS-L page