Suppose I have a time-series variable x as follows.
data _;
do t=1 to 1000;
x+rannor(1);
output;
end;
run;
I can do PROC GPLOT to draw the time-series plot.
filename _ "!userprofile\desktop\_.png";
goption gsfname=_ device=png gsfmode=replace;
ods results=off;
symbol i=join;
proc gplot;
format t yymmn6.;
plot x*t;
run;
ods results=on;
quit;
Then, the following is the result.
This is reasonable as there is nearly no gap before and after the time span. Let's assume, however, t from 1001 to 2000 rather than 1 to 1000.
data _;
do t=1001 to 2000;
x+rannor(1);
output;
end;
run;
Then, SAS spits out the following result.
As above, SAS makes a significantly larger gap before the plot starts. I cannot eliminate the gap even after subsetting using WHERE in PROC GPLOT. I cannot understand the way SAS works at this point—there must be no difference as far as I know—but can I control the gap size?
@Junyong wrote:
Suppose I have a time-series variable x as follows.
data _; do t=1 to 1000; x+rannor(1); output; end; run;
I can do PROC GPLOT to draw the time-series plot.
filename _ "!userprofile\desktop\_.png"; goption gsfname=_ device=png gsfmode=replace; ods results=off; symbol i=join; proc gplot; format t yymmn6.; plot x*t; run; ods results=on; quit;
Then, the following is the result.
This is reasonable as there is nearly no gap before and after the time span. Let's assume, however, t from 1001 to 2000 rather than 1 to 1000.
data _; do t=1001 to 2000; x+rannor(1); output; end; run;
Then, SAS spits out the following result.
As above, SAS makes a significantly larger gap before the plot starts. I cannot eliminate the gap even after subsetting using WHERE in PROC GPLOT. I cannot understand the way SAS works at this point—there must be no difference as far as I know—but can I control the gap size?
Probably time to move to the more modern SGPLOT but to explain why you Axis appears as shown: You are using a default Axis. Without specific rules to create axis tick marks SAS uses an algorithm based on the ranges of values and for date and time formats, some of the format information. The larger the range of values the more likely to get your "gap" to place "nice" intervals for the tick marks. For a learning point you might change the format to yyq. instead, which displays year and calendar quarter, and see what that does to the "gap"
To control appearance of the AXIS values you have 1) assign properties to an Axis statement and 2) tell the procedure which axis definition to use for the axis using the HAXIS= or VAXIS= to use that Axis definition. Or you can list specific values on an HAXIS statement.
You might try adding HAXIS =( '01OCT1962'd to '01JUL1965'd by quarter) so the first tick is for Oct 1962 instead of July.
proc gplot; format t yymmn6.; plot x*t / HAXIS =( '01OCT1962'd to '01JUL1965'd by quarter) ; run;
Can you just use sgplot?
proc sgplot data=_;
format t yymmn6.;
series x=t y=x;
xaxis min=1004;
run;
@Junyong wrote:
Suppose I have a time-series variable x as follows.
data _; do t=1 to 1000; x+rannor(1); output; end; run;
I can do PROC GPLOT to draw the time-series plot.
filename _ "!userprofile\desktop\_.png"; goption gsfname=_ device=png gsfmode=replace; ods results=off; symbol i=join; proc gplot; format t yymmn6.; plot x*t; run; ods results=on; quit;
Then, the following is the result.
This is reasonable as there is nearly no gap before and after the time span. Let's assume, however, t from 1001 to 2000 rather than 1 to 1000.
data _; do t=1001 to 2000; x+rannor(1); output; end; run;
Then, SAS spits out the following result.
As above, SAS makes a significantly larger gap before the plot starts. I cannot eliminate the gap even after subsetting using WHERE in PROC GPLOT. I cannot understand the way SAS works at this point—there must be no difference as far as I know—but can I control the gap size?
Probably time to move to the more modern SGPLOT but to explain why you Axis appears as shown: You are using a default Axis. Without specific rules to create axis tick marks SAS uses an algorithm based on the ranges of values and for date and time formats, some of the format information. The larger the range of values the more likely to get your "gap" to place "nice" intervals for the tick marks. For a learning point you might change the format to yyq. instead, which displays year and calendar quarter, and see what that does to the "gap"
To control appearance of the AXIS values you have 1) assign properties to an Axis statement and 2) tell the procedure which axis definition to use for the axis using the HAXIS= or VAXIS= to use that Axis definition. Or you can list specific values on an HAXIS statement.
You might try adding HAXIS =( '01OCT1962'd to '01JUL1965'd by quarter) so the first tick is for Oct 1962 instead of July.
proc gplot; format t yymmn6.; plot x*t / HAXIS =( '01OCT1962'd to '01JUL1965'd by quarter) ; run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.