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

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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
  • 1414 views
  • 0 likes
  • 2 in conversation