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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: