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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

4 REPLIES 4
ballardw
Super User

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.

GraphGuy
Meteorite | Level 14

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

angorwat
Calcite | Level 5

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.

GraphGuy
Meteorite | Level 14

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1078 views
  • 1 like
  • 3 in conversation