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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.