I want to draw a time-series using SGPLOT. I want to display plane and log versions together because the series is exponential. The only problem is the legend, which repeats the name x just twice. Can I give separate names in this case? The following is the code.
data have;
do t=1 to 5000;
if t=1 then x=1;
else x=x*(1+0.1/12+0.05/sqrt(12)*rannor(1));
output;
end;
run;
ods listing gpath="!userprofile\desktop\";
proc sgplot;
series x=t y=x;
series x=t y=x/y2axis;
xaxis display=(nolabel);
yaxis display=(nolabel);
y2axis display=(nolabel) type=log;
run;
Thanks for your help.
From SAS 9.4M5, you can do something like this
data have;
do t=1 to 5000;
if t=1 then x=1;
else x=x*(1+0.1/12+0.05/sqrt(12)*rannor(1));
output;
end;
run;
proc sgplot;
series x=t y=x;
series x=t y=x/y2axis;
xaxis display=(nolabel);
yaxis display=(nolabel);
y2axis display=(nolabel) type=log;
legenditem type=line name='x1' / label='x' lineattrs=GraphData1;
legenditem type=line name='x2' / label='x (Log)' lineattrs=GraphData2;
keylegend 'x1' 'x2';
run;
Result:
From SAS 9.4M5, you can do something like this
data have;
do t=1 to 5000;
if t=1 then x=1;
else x=x*(1+0.1/12+0.05/sqrt(12)*rannor(1));
output;
end;
run;
proc sgplot;
series x=t y=x;
series x=t y=x/y2axis;
xaxis display=(nolabel);
yaxis display=(nolabel);
y2axis display=(nolabel) type=log;
legenditem type=line name='x1' / label='x' lineattrs=GraphData1;
legenditem type=line name='x2' / label='x (Log)' lineattrs=GraphData2;
keylegend 'x1' 'x2';
run;
Result:
Or you can do this
proc sgplot;
series x=t y=x / legendlabel='x';
series x=t y=x / y2axis legendlabel='x (Log)';
xaxis display=(nolabel);
yaxis display=(nolabel);
y2axis display=(nolabel) type=log;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.