BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

SGPlot.png

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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:

 

 

SGPlot4.png

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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:

 

 

SGPlot4.png

PeterClemmensen
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 815 views
  • 0 likes
  • 2 in conversation