BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JackM22
Fluorite | Level 6

I was able to produce this

JackM22
Fluorite | Level 6

Thank you again for your assistance.  The attached PDF file is the chart I was able to produce

 

Jack E Mohr

Jay54
Meteorite | Level 14

Since your x-axis is numeric, you are getting the "random" jittering.  To get the "Turnip" type jitter, the x-axis needs to be discrete.

JackM22
Fluorite | Level 6

How do I make the numeric SAS variable, Year, a discrete variable? Can you point me to any documentation?

 

Here is the code I used to produced the attached graphic:

 

/* This program requires SAS 9.4 TS Level 1M1 or later */
%let gpath='.';
%let dpi=100;
 
proc template;
  define style styles.blueBG;
    parent = Styles.htmlblue;
    style graphbackground  from graphbackground
      "Abstract colors used in graph styles" /
      color   = cxf0f0f7;
  end;
run;
 
/*--Orthopedic Hospital Dischares H--*/
data orthosurg;
  set WORK.ORTHOSURGX;
run;
 
ods html close;
 
/*--Discrete X Axis--*/
ods listing style=styles.blueBG image_dpi=&dpi gpath=&gpath;
ods graphics / reset width=10in height=6.5in imagename='Jitter_94';
title 'Hip Replacement Surgeries per 1000 Medicare Enrollees for Hospital Referral Regions';
footnote j=l h=0.9 'This graphs uses jitter on discrete X axis';
proc sgplot data=orthosurg noautolegend;
  scatter x=Year y=HipReplacementper1K9313/ jitter
    markerattrs=graphdata1(size=9 symbol=circlefilled)
    filledoutlinedmarkers markeroutlineattrs=(thickness=0)
    markerfillattrs=graphdata1 dataskin=sheen;
  vbox HipReplacementper1K9313 / category=Year fillattrs=(transparency=0.5) nooutliers;
  xaxis display=(nolabel);
  yaxis grid;
  run;
 
title;
footnote;
Jay54
Meteorite | Level 14

Try:

xaxis display=(nolabel) type=discrete;

 

If that does not work, create and use a new character column that contains the year.

JackM22
Fluorite | Level 6
That looks better (see attached file) Ideally the dots would not overlap. I will try running the program for just one or two years worth of data to make room for scattering the dots.
 
I like the graphic with the box and whiskers overlay, but this was not my origional goal. My goal was to produce turnip charts that look like those in the Dartmouth Atlas of Healthcare (see attched file) where the dots are nicely distributed with minimal overlap
Jay54
Meteorite | Level 14

A graph like the sample from the "Dartmouth Atlas" works for a small number of categories on th x-axis and also with a relatively small number of observations in each row.  This method may not work for other cases as there may not be enough space to place all the dots in each row even with a very small 1 pixel dot.  It helps to have a graph that can scale to handle different data.  

 

In the graph below, the observations in each horizontal bin are displayed using a bar where the length of the bar is proportional to the number of observations.  Each observation is not shown, but the count in each bin can be shown (not necessary).  This process is scalable to any number of categories on the x-axis and any number of observations in each row (bin).  I will post the code shortly.

 

TurnipPanel.png.  

 

 TurnipPanelLine.png

 

Rick_SAS
SAS Super FREQ

There have been several discussions recently about overlaying scatter plots or series plots on top of box plots.  I've summarized some of my thoughts and presented some examples on my blog:

1. Overlay plots on a box plot in SAS: Discrete X axis

2. Overlay plots on a box plot in SAS: Continuous X axis

JackM22
Fluorite | Level 6

There is a reference to jitterwidth, but I was unable to find an example or an explaination of how to use  it.

 

Note: The Turnip Charts in the Dartmouth Atlas are produced using SAS. They have 306 observations which is the same number I have in my data for each year.  There must be a way to set parameters in SAS to disperse the points in the Turnip Chart

 

Even when I plot data for just one year, the dots overlap and are not spread out much

 

Here is the SAS code I used:

 

/* This program requires SAS 9.4 TS Level 1M1 or later */
%let gpath='.';
%let dpi=100;
 
proc template;
  define style styles.blueBG;
    parent = Styles.htmlblue;
    style graphbackground  from graphbackground
      "Abstract colors used in graph styles" /
      color   = cxf0f0f7;
  end;
run;
 
/*--Medical Discharges 1993 to 2013--*/
data meddisch;
  set WORK.MEDDISCH93TO13;
    where Year = 2013;
    run;
 
ods html close;
 
/*--Discrete X Axis--*/
ods listing style=styles.blueBG image_dpi=&dpi gpath=&gpath;
ods graphics / reset width=10in height=7.5in imagename='Jitter_94';
title 'Bacterial Pneumonia Discharges per 1000 Medicare Enrollees for Hospital Referral Regions';
footnote j=l h=0.9 'This graphs uses jitter on discrete X axis';
proc sgplot data=meddisch noautolegend;
  scatter x=Year y=BacterialPneumoniaDisch1k9313 / jitter
    markerattrs=graphdata1(size=9 symbol=circlefilled)
    filledoutlinedmarkers markeroutlineattrs=(thickness=0)
    markerfillattrs=graphdata1 dataskin=sheen;
  vbox BacterialPneumoniaDisch1k9313 / category=Year fillattrs=(transparency=0.5) nooutliers;
  xaxis display=(nolabel) type=discrete;
  /*xaxis display=(nolabel);*/
  yaxis grid;
  run;
 
title;
footnote;
JackM22
Fluorite | Level 6

Your Blog post with code is interesting.

 

I would like to adapt the code you posted to my data, but was unable to make it work. Perhaps, the way my dataset is formatted is problematic, or the code needs to be modified to reflect the characteristics of my data.

 

I have attached an excell file that was created by exporting the SAS data set, MEDDISCH93TO13.

 

Can the graphics shown in your blog post be created using MEDDISCH93TO13? I suspect I have missed something simple

 

Jack Mohr

Asheville, NC

 

Jay54
Meteorite | Level 14

 

TurnipPanelExcel.png

 

%let gpath='.';
%let dpi=200;
ods html close;
ods listing gpath=&gpath image_dpi=&dpi;

/*--Read datra from Excel--*/
proc import datafile='C:\MEDDISCH93TO13.xlsx' 
     dbms=XLSX out=ExcelData replace;
run;

/*--Get bin counts by year--*/
ods output sgpanel=dataExcel;
ods graphics / reset imagename='HistPanelExcel';
proc sgpanel data=ExcelData(where=(year>2006));
  panelby year / layout=rowlattice rows=4 novarname;
  histogram BacterialPneumoniaDisch1k9313 / scale=count binwidth=1;
run;

/*--Keep only non-zero bins--*/
data nonzero;
  set dataExcel (rename=(BIN_BACTERIALPNEUMONIADISCH1K__X=y 
                    BIN_BACTERIALPNEUMONIADISCH1K__Y=max));
  if max>0;
  zero=0;
  ylbl=0;
run;

/*--Make mirrored data for a HighLow plot--*/
data turnip;
  length label $40;
  set nonzero;
  by year;
  if first.year then label=year;
  min=-max;
run;

/*--Create Spark-Plug Graph--*/
ods graphics / reset width=5in height=3in imagename='TurnipPanelExcel';
title 'Distribution of BACTERIALPNEUMONIADISCH1K by Year';
proc sgpanel data=turnip noautolegend;
  panelby year / novarname layout=columnlattice 
          columns=4 noborder noheader;
  highlow y=y low=min high=max / type=bar barwidth=1 
          fillattrs=(color=lightgray) lineattrs=(color=black);
  colaxis display=none;
  rowaxis offsetmin=0.15 display=(noticks noline nolabel) grid;
  text y=y x=zero text=max /  strip textattrs=(size=5);
  text y=ylbl x=zero text=label /  strip splitpolicy=split 
       position=bottom contributeoffsets=none;
run;
JackM22
Fluorite | Level 6

I was given this code for making turnip graphs. Can you make sense of this code?

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 28 replies
  • 3287 views
  • 0 likes
  • 4 in conversation