Basically, I have data that is in a monthly interval. However, I need my graph to display the rate associated with the y axis in yearly intervals. Proc GPLOT and Proc Template were either cutting off the series line at either Jan15 or adding a bunch of white space and another tick mark for January 16. Your code, which I designated as the solution was adaptable to get as close as possible to what I need. In my first proc sql statement, I already had my months in numeric formats and I kept them all, but I did my other date formats here, and added the columns I need for annotations. In your data step, I pulled everything I need from the table I created in sql, did my conversion of the January sasdates to my own format, made sure all other months were missing--not sure why we are adding a row number, but I kept that. Next I did the annotation exactly as you coded. Then the Plot gave me almost exactly what I wanted. I hate to be greedy, but what are the functions in sgplot that would let us move the tickmarks into the graph? GTL has tickstyle=inside, but I couldn't find an equivalent for sgplot. Also, is there a way to change the colors of the grid lines? Thank you very much for all your assistance.
My final code:
proc sql noprint;
create table CP_JO as
SELECT
round((a.value/b.jo_sa), 0.1) as jopu,
b.year
b.month,
MDY(b.month, 01, b.year) format=date9. as sasdate,
6000 as r1,
0 as y,
MDY(b.month, 01, b.year) format=daslt. as date
FROM
cps a, jlt2 b
where a.month=b.month and a.year=b.year
order by year, month;
quit;
data bruno;
set cp_jo;
if year>2004;
if month = 1 then do;
myDate_c = put(sasdate, daslt.);
end;
else do;
call missing(myDate_c);
end;
row + 1;
output;
;
keep year month sasdate jopu y0 r1 mydate_c row;
run;
%SGANNO
data jp_anno;
set bruno(keep=sasdate myDate_c );
where myDate_c not is missing;
%SGTEXT(
LABEL=myDate_c
, ANCHOR= "bottom"
, TEXTCOLOR="black"
, X1SPACE="datavalue"
, X1=sasdate
, y1space="WALLPERCENT"
, y1=-8
, LAYER="front"
, rotate=45
)
run;
proc sgplot data=cp_jo pad=(bottom=10pct) sganno=jp_anno noautolegend;
band y=r1 lower="01DEC07"d upper="01JUN09"d / transparency=.8 fillattrs=(color=gray);
series x=sasdate y=jopu;
xaxis type=time
ranges=(
"01JAN2005"d - "01aug2015"d
)
display=(novalues nolabel )
;
yaxis
grid
;
YAXIS LABEL = ' ' GRID VALUES = (0 TO 7 BY 1);
run;
Here's an abbreviated section of the bruno table from the data step above:
jopu
year
month
sasdate
r1
myDate_c
row
2.2
2005
1
1-Jan-2005
6000
Jan-05
1
2.1
2005
2
1-Feb-2005
6000
2
2
2005
3
1-Mar-2005
6000
3
1.9
2005
4
1-Apr-2005
6000
4
2
2005
5
1-May-2005
6000
5
1.9
2005
6
1-Jun-2005
6000
6
1.8
2005
7
1-Jul-2005
6000
7
1.8
2005
8
1-Aug-2005
6000
8
1.8
2005
9
1-Sep-2005
6000
9
1.8
2005
10
1-Oct-2005
6000
10
1.7
2005
11
1-Nov-2005
6000
11
1.7
2005
12
1-Dec-2005
6000
12
1.7
2006
1
1-Jan-2006
6000
Jan-06
13
1.7
2006
2
1-Feb-2006
6000
14
1.6
2006
3
1-Mar-2006
6000
15
1.6
2006
4
1-Apr-2006
6000
16
1.6
2006
5
1-May-2006
6000
17
1.6
2006
6
1-Jun-2006
6000
18
And here is what the anno table looks like:
ANCHOR
FUNCTION
LABEL
LAYER
TEXTCOLOR
X1SPACE
Y1SPACE
ROTATE
X1
Y1
bottom
TEXT
Jan-05
front
black
datavalue
WALLPERCENT
45
16437
-8
bottom
TEXT
Jan-06
front
black
datavalue
WALLPERCENT
45
16802
-8
bottom
TEXT
Jan-07
front
black
datavalue
WALLPERCENT
45
17167
-8
bottom
TEXT
Jan-08
front
black
datavalue
WALLPERCENT
45
17532
-8
bottom
TEXT
Jan-09
front
black
datavalue
WALLPERCENT
45
17898
-8
bottom
TEXT
Jan-10
front
black
datavalue
WALLPERCENT
45
18263
-8
bottom
TEXT
Jan-11
front
black
datavalue
WALLPERCENT
45
18628
-8
bottom
TEXT
Jan-12
front
black
datavalue
WALLPERCENT
45
18993
-8
bottom
TEXT
Jan-13
front
black
datavalue
WALLPERCENT
45
19359
-8
bottom
TEXT
Jan-14
front
black
datavalue
WALLPERCENT
45
19724
-8
bottom
TEXT
Jan-15
front
black
datavalue
WALLPERCENT
45
20089
-8
And the plot is attached. I still would love to be able to move the tickmarks inside and to make the gridlines black. Much thanks. I think this thread will be a great reference.
... View more