Data visualization with SAS programming

GPLOT - Xaxis show twice

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

GPLOT - Xaxis show twice

Hi 

 

I am trying to built a line graph for two regions in the same graph to compare the volume by month wise, but the scale (month) is showing twice in the x-axis if i run the code without the where clause for region.

But when i split the data using where clause and run the GPLOT separtely (as below ) it works fine.

 

Can you please advise how to draw a line graph for the below dataset in a single chart.

P.S - i cant use SGPLOT as i am using 9.1 version SAS in 4.1 SAS EG 

 

My summary table

Month

Region

count

Apr-17

Asia

2716

Apr-17

Europe

488

Dec-16

Asia

5082

Dec-16

Europe

882

Feb-17

Asia

4009

Feb-17

Europe

775

Jan-17

Asia

4689

Jan-17

Europe

837

Mar-17

Asia

4903

Mar-17

Europe

1073

Nov-16

Asia

5080

Nov-16

Europe

1001

 

GOPTIONS horigin=0 vorigin=0;
symbol1 interpol=join
        value=dot
        color=_style_;

symbol2 interpol=join
        value=C
        font=marker
        color=_style_ ;

axis1 
      label=none
      major=(height=2)
      minor=(height=1);

axis2 
      label=none
      major=(height=2)
      minor=(height=1)
      ;
legend1 label=none
        position=(top center inside)
        mode=share
	  ;
TITLE;
TITLE1 "Volume by region";

PROC GPLOT DATA =file1(where=( region ='Asia'));
PLOT count*month = region /
	VAXIS=AXIS1	vminor=1
	HAXIS=AXIS2 hminor=4
FRAME;
RUN; QUIT;

PROC GPLOT DATA =file1(where=( region ='Europe'));
PLOT count*month = region /
	VAXIS=AXIS1	vminor=1
	HAXIS=AXIS2 hminor=4
FRAME;
RUN; QUIT;

 


Accepted Solutions
Solution
‎05-02-2017 12:34 AM
SAS Employee
Posts: 980

Re: GPLOT - Xaxis show twice

data file1;
length month_string $20 region $20;
input Month_string;
month_string='01-'||trim(left(month_string));
format month date9.;
month=.; month=input(trim(left(month_string)),anydtdte9.);
input Region;
input count;
datalines;
Apr-17
Asia
2716
Apr-17
Europe
488
Dec-16
Asia
5082
Dec-16
Europe
882
Feb-17
Asia
4009
Feb-17
Europe
775
Jan-17
Asia
4689
Jan-17
Europe
837
Mar-17
Asia
4903
Mar-17
Europe
1073
Nov-16
Asia
5080
Nov-16
Europe
1001
;
run;

symbol1 interpol=join
value=dot
color=_style_;

symbol2 interpol=join
value=C
font=marker
color=_style_ ;

axis1
label=none
major=(height=2)
minor=(height=1);

axis2 order=('01nov2016'd to '01apr2017'd by month)
offset=(3,3)
label=none
major=(height=2)
minor=none
;
legend1 label=none
position=(top center inside)
mode=share
;
TITLE;
TITLE1 "Volume by region";

proc sort data=file1 out=file1;
by region month;
run;

PROC GPLOT DATA =file1;
format month monyy7.;
PLOT count*month = region /
VAXIS=AXIS1 vminor=1
HAXIS=AXIS2 hminor=4
FRAME;
RUN; QUIT;

 

graph2.png

View solution in original post


All Replies
Super User
Posts: 11,118

Re: GPLOT - Xaxis show twice

What format does your month variable have?

A date value that does not display the day of the month could well have a different day and be hidden by the format. Then proc gplot would show both but appear the same.

 

Note that if you summarized the data using proc means or summary that you likely have the earliest date for a given month/year that was in your data. Check this by changing the format to something that shows the day of the month as well such as Date7. or mmddyy8.

SAS Employee
Posts: 980

Re: GPLOT - Xaxis show twice

I think you want something like this:

 

data file1;
length month_string $20 region $20;
input Month_string;
month_string='15-'||trim(left(month_string));
format month date9.;
month=.; month=input(trim(left(month_string)),anydtdte9.);
input Region;
input count;
datalines;
Apr-17
Asia
2716
Apr-17
Europe
488
Dec-16
Asia
5082
Dec-16
Europe
882
Feb-17
Asia
4009
Feb-17
Europe
775
Jan-17
Asia
4689
Jan-17
Europe
837
Mar-17
Asia
4903
Mar-17
Europe
1073
Nov-16
Asia
5080
Nov-16
Europe
1001
;
run;

symbol1 interpol=join
value=dot
color=_style_;

symbol2 interpol=join
value=C
font=marker
color=_style_ ;

axis1
label=none
major=(height=2)
minor=(height=1);

axis2
label=none
major=(height=2)
minor=(height=1)
;
legend1 label=none
position=(top center inside)
mode=share
;
TITLE;
TITLE1 "Volume by region";

 

proc sort data=file1 out=file1;
by region month;
run;

 

PROC GPLOT DATA =file1;
PLOT count*month = region /
VAXIS=AXIS1 vminor=1
HAXIS=AXIS2 hminor=4
FRAME;
RUN; QUIT;

 

 

regions.png

Occasional Contributor
Posts: 18

Re: GPLOT - Xaxis show twice

[ Edited ]

Thanks Rob, its working as expected. but two questions. 

.1) I dont have May month data but it in x-axis it still shows May 2017, how can we remove it

 2) Is there way to show the x-axis as 'NOV2016' than 01NOV2016.

 

@ballardw 

 

thanks, I will try your option too.

Solution
‎05-02-2017 12:34 AM
SAS Employee
Posts: 980

Re: GPLOT - Xaxis show twice

data file1;
length month_string $20 region $20;
input Month_string;
month_string='01-'||trim(left(month_string));
format month date9.;
month=.; month=input(trim(left(month_string)),anydtdte9.);
input Region;
input count;
datalines;
Apr-17
Asia
2716
Apr-17
Europe
488
Dec-16
Asia
5082
Dec-16
Europe
882
Feb-17
Asia
4009
Feb-17
Europe
775
Jan-17
Asia
4689
Jan-17
Europe
837
Mar-17
Asia
4903
Mar-17
Europe
1073
Nov-16
Asia
5080
Nov-16
Europe
1001
;
run;

symbol1 interpol=join
value=dot
color=_style_;

symbol2 interpol=join
value=C
font=marker
color=_style_ ;

axis1
label=none
major=(height=2)
minor=(height=1);

axis2 order=('01nov2016'd to '01apr2017'd by month)
offset=(3,3)
label=none
major=(height=2)
minor=none
;
legend1 label=none
position=(top center inside)
mode=share
;
TITLE;
TITLE1 "Volume by region";

proc sort data=file1 out=file1;
by region month;
run;

PROC GPLOT DATA =file1;
format month monyy7.;
PLOT count*month = region /
VAXIS=AXIS1 vminor=1
HAXIS=AXIS2 hminor=4
FRAME;
RUN; QUIT;

 

graph2.png

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 277 views
  • 1 like
  • 3 in conversation