Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC...

19
Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

Transcript of Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC...

Page 1: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

Lydia Li

TransUnion Canada

One Step Ahead :

from PROC GPLOT to PROC SGPLOT

MAY, 2015

Page 2: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

2 | © TransUnion. LLC All Rights Reserved

SAS Graph Procedures

PROC GPLOT

PROC SGPLOT

The advantages of SGPLOT over GPLOT

Q&A

Agenda

Page 3: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

3 | © TransUnion. LLC All Rights Reserved

Data Source

New in SAS 9.3

a library of data sets

consisting of GfK

GeoMarketing digital,

vector-based maps.

Page 4: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

4 | © TransUnion. LLC All Rights Reserved

• Different types of graphs & distinct graph procedures

Creating graphs within the SAS environment

proc gchart data=sashelp.class;

pie weight;

run;

Pie Graph

proc g3d data=hill;

plot y*x=z;

run;

3D GraphRegression Equation

proc sgplot data=sashelp.class;

reg x=height y=weight;

run;

Page 5: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

5 | © TransUnion. LLC All Rights Reserved

Syntax

PROC GPLOT <DATA=input-data-set>

<Option(s)=Statement(s)>;

PLOT plot-request(s) </option(s)>;

PLOT2 plot-request(s) </option(s)>;

RUN;

PROC GPLOT

OR

Overlay:

At MOST 2 graphs

BUBBLE plot-request(s) </option(s)>;

BUBBLE2 plot-request(s) </option(s)>;

Page 6: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

6 | © TransUnion. LLC All Rights Reserved

What can we do using PROC GPLOT?

title1 "Students' Height and Weight";

title2 "Female Only";

footnote1 "weight=star height=dot";

axis1 label=none order=(10 to 17 by 1);

axis2 label=("weight/height");

symbol1 interpol=none value=star c=green h=2;

symbol2 interpol=none value=dot h=2;

• Example 1: display female students’ heights and weights with PROC GPLOT

proc gplot data=sashelp.class;

plot (weight height)*age/ overlay

haxis=axis1

vaxis=axis2;

where sex="F";

run;

quit;

Plan Ahead GPLOT Outcomes

Page 7: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

7 | © TransUnion. LLC All Rights Reserved

What can we do using PROC GPLOT?

title1 "Shoes Sales";

title2 "Total Sales and Number of Stores at

Toronto";

axis1 offset=(5,5);

axis2 order=(0 to 90000 by 10000) minor=none;

• Example 2: bubble chart with PROC GPLOT

proc gplot data=sashelp.shoes;

bubble Sales*Product=Stores/ haxis=axis1

vaxis=axis2;

where Region="Canada"

and Subsidiary="Toronto";

run;

quit;

Plan Ahead GPLOT Outcomes

Page 8: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

8 | © TransUnion. LLC All Rights Reserved

• Syntax

• 3-step Process

• Graph Types

Short Summary for PROC GPLOT

PROC GPLOT <DATA=input-data-set>

<Option(s)=Statement(s)>;

Bubble / Plot plot-request(s) </option(s)>;

< Bubble2 / Plot2 plot-request(s) </option(s)>; >

RUN;

Overlay:

At MOST 2 graphs

Plan Ahead GPLOT Outcomes

• Scatter plot

• Overlay plot

• Logarithm plot

• Bubble chart

Page 9: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

9 | © TransUnion. LLC All Rights Reserved

Syntax

PROC SGPLOT <DATA=input-data-set>;

GraphType X=var Y=var / < option(s)>;

< Optional Statements>;

RUN;

PROC SGPLOT

Graph Type

•Ellipse

•Hbox/Vbox

•Histogram

•Density

•Etc.

Build-in Options

New procedure starts from SAS 9.2

Overlay:

>= 2 graphs

Page 10: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

10 | © TransUnion. LLC All Rights Reserved

New Procedure: PROC SGPLOT

• Example 1: using Box Plot to display students’ height and weight

proc sgplot data=sashelp.class;

hbox height/category=sex;

hbox weight/category=sex;

title "Box Plot of Students' Height and Weight";

xaxis label="Height/Weight";

run;

SGPLOT Outcomes

Page 11: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

11 | © TransUnion. LLC All Rights Reserved

New Procedure: PROC SGPLOT

• Example 2: observe the trend of unit sale using PROC SGPLOT

proc sgplot data=Sashelp.Pricedata;

series x=date y=sale;

refline 400 500;

title "The Trend of Unit Sale";

where productName="Product1";

run;

SGPLOT Outcomes

Page 12: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

12 | © TransUnion. LLC All Rights Reserved

New Procedure: PROC SGPLOT

• Example 3: create map for US using PROC SGPLOT

US map

(using the SAS/GRAPH MAPSGFK.US map data set)

+

Self-created response data

SAS Support---Sample 53367: Create a map with the SGPLOT procedure

Page 13: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

13 | © TransUnion. LLC All Rights Reserved

• Syntax

• 2-step Process

• Graph Types

Short Summary for PROC SGPLOT

PROC SGPLOT < option(s)>;

GraphType X=var Y=var / < option(s)>;

< Optional Statements>;

RUN;

Overlay:

As many as you want

SGPLOT Outcomes

• Scatter plot

• Overlay plot

• Logarithm plot

• Bubble chart

• Bar chart

• Box plot

• Time series

• Map etc.

Page 14: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

14 | © TransUnion. LLC All Rights Reserved

1. Shorter process: Don’t need to plan ahead

The advantages of PROC SGPLOT comparing with PROC GPLOT

Plan Ahead GPLOT Outcomes

SGPLOT Outcomes

• Symbol statement

• Axis statement

Build-in options• REFLINE option (reference line)

• XAXIS & YAXIS options

• FILLATTRS

• LINEATTRS ATTRIBUTE options

• MARKERATTRS

3 STEPS

2 STEPS

Page 15: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

15 | © TransUnion. LLC All Rights Reserved

2. More graph types

The advantages of PROC SGPLOT comparing with PROC GPLOT

GPLOT SGPLOT

• Scatter plot

• Overlay plot

• Logarithm plot

• Bubble chart

• Scatter plot

• Overlay plot

• Logarithm plot

• Bubble chart

• Bar chart

• Map

• Box plot

• Etc.

LIMITED graph options

Page 16: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

16 | © TransUnion. LLC All Rights Reserved

proc sort data=sashelp.class out=class; by sex;run;

proc freq data=class noprint;

table age / out=gplot_class;

by sex;

run;

symbol c=vibg i=needle v=none w=40;

axis1 order=(0 to 3 by 1) label=("Frequency");

axis2 order=(10 to 17 by 1);

title "Sex=M";

proc gplot data=gplot_class;

plot count*age / vaxis=axis1 haxis=axis2;

where sex='M';

run;

quit;

Bar Chart

proc sort data=sashelp.class out=class; by sex; run;

proc sgplot data=class;

vbar age / FILLATTRS=(color=vibg);

by sex;

where sex='M';

run;

quit;

GPLOT SGPLOT

1. Automatically create frequency variable

2. Simple and clear attribute options

3. Set up the perfect suitable range

Y-axis begins from 1

instead of 0

Page 17: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

17 | © TransUnion. LLC All Rights Reserved

1. Shorter process: Don’t need to plan ahead

2. More graph options

3. Better appearance axes automatically create

4. Overlay >= 2 plots

Conclusion: the Advantages of PROC SGPLOT

SGPLOT Build-in options Outcomes

• Scatter plot

• Overlay plot

• Logarithm plot

• Bubble chart

• Bar chart

• Map

• Box plot

• Etc.

Page 18: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

18 | © TransUnion. LLC All Rights Reserved

Q&A

References

• Shruthi Amruthnath, Experis Business Analytics, Portage, MI : PROC SGPLOT over PROC GPLOT

• Philip Mason, Wood Street Consulting, Wallingford, Oxfordshire, England: Introduction to SAS®/Graph

• Susan J. Slaughter, Avocet Solutions, Davis, CA Lora D. Delwiche, University of California, Davis, CA : Using PROC

SGPLOT for Quick High-Quality Graphs

Page 19: Li Proc SGPlot May2015 - SAS · Lydia Li TransUnion Canada One Step Ahead : from PROC GPLOT to PROC SGPLOT MAY, 2015

19 | © TransUnion. LLC All Rights Reserved

• Contact Information

Thank you

• Appreciate the helpful suggestions and advises from Justin and Peter

Co-op student

@TransUnion

From Jan. - End of Aug.

Email: [email protected]

Phone:905-340-1000 ext.2181

Undergraduate student

@McMaster University

Graduation date: Apr, 2017

Email:[email protected]

Phone:289-921-0680