Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
t75wez1
Pyrite | Level 9

Hello,

Inspired by Rick Wicklin who created a nice mosaic plot by using airline crash data, I wonder if the percentage #s from "proc freq" can be annotated on the mosiac plot. That's would be easy to present in the idea of "numbers within graph".

 

Hope some SAS guru here can help me get the desired outcome.

 

Below is the short version of Rick's SAS code,  The attached you'll find raw data in CSV format and PPT file including current result and desired result.

 

Thanks,

 

Ethan

 

 

 

PROC IMPORT OUT= WORK.CrashRaw

/* CHANGE the next line to point to the location of the FlightRisk.csv file */

DATAFILE= "h:\temp\FlightRisk.csv"

DBMS=CSV REPLACE;

GETNAMES=YES;

DATAROW=3;

RUN;

/* Do some data cleansing */

data Crash;

label Phase="Flight Phase" Cause="Cause of Crash";

set CrashRaw(rename=(cause=LongCause meta=Cause));

 

Year = Year(Date);

if Phase="ap" | substr(upcase(Phase),1,8)="APPROACH" | Phase="Landing" then Phase="landing";

if Phase="grounded" then Phase="standing";

if Phase="initial takeo" | Phase="take off" | Phase="Takeoff" | Phase="takeoff" |Phase="initial_climb" then Phase="take-off";

if Phase="en_route" then Phase="en route";

if Cause="human_error" then Cause="human error";

 

/* order by frequency */

if Phase="landing" then PhaseN=1;

else if Phase="en route" then PhaseN=2;

else if Phase="take-off" then PhaseN=3;

else if Phase="standing" then PhaseN=4;

else if Phase="unknown" then PhaseN=5;

if Cause="criminal" then CauseN=1;

else if Cause="unknown" then CauseN=2;

else if Cause="mechanical" then CauseN=3;

else if Cause="weather" then CauseN=4;

else if Cause="human error" then CauseN=5;

run;

 

 

 

ods _ALL_ close;

ods listing gpath="H:\Temp" image_dpi=300;

 

 

ods graphics on / width=600px height=600px reset=index outputfmt=PNG imagename="crash_mosiac" ;

 

 

proc freq data=Crash order=data;

tables Cause*Phase / nocum norow nocol

plots=(mosaic(square));

run;

ods graphics off;

 

1 REPLY 1
ballardw
Super User

Many of the plots associated with analysis procedures have vary limited options. You may have to summarize the data and go to Graphic Template Language and a MOSAICPLOTPARM block of code to control appearances.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1461 views
  • 0 likes
  • 2 in conversation