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;
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;
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.
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;
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.
thanks, I will try your option too.
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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.