Hello,
Can some one help me if there are any options to control tickvales on a log scale while we use proc template or proc sgplot?
For example, if I go with log base = 10, then scale will have a tick values at 1, 10, 100, 1000, 10000..... Can we control these tick vales to show only fewer values then the default values?
rowaxisopts=( type = log logopts=( base = 10))
Sure. IN SGPLOT you can use the VALUES= option to specify the values for ticks. It works for linear and for logarithmic axes:
data Have;
call streaminit(12345);
do i = 1 to 1000;
t = abs(rand("normal", 0, 5));
x = exp(t);
y = rand("Normal");
if abs(x)>1 then output;
end;
run;
proc sgplot data=Have;
scatter x=x y=y;
xaxis type=log logbase=10
values=(10 100 500 1000 10000 50000);
run;
You can do the same thing in GTL, but the option is called TICKVALUELIST= and it is used like this:
xaxisopts=(type=log logopts=(tickvaluelist=(10 100 500 1000 10000 50000)
Sure. IN SGPLOT you can use the VALUES= option to specify the values for ticks. It works for linear and for logarithmic axes:
data Have;
call streaminit(12345);
do i = 1 to 1000;
t = abs(rand("normal", 0, 5));
x = exp(t);
y = rand("Normal");
if abs(x)>1 then output;
end;
run;
proc sgplot data=Have;
scatter x=x y=y;
xaxis type=log logbase=10
values=(10 100 500 1000 10000 50000);
run;
You can do the same thing in GTL, but the option is called TICKVALUELIST= and it is used like this:
xaxisopts=(type=log logopts=(tickvaluelist=(10 100 500 1000 10000 50000)
Thank you so much for your guidance.
Could you also suggest me on the following..
Once we have the desired tick values, I want to align Y1 values with Y2 axis values with a formula of 0.2 on Y2 corresponds to 50 on Y1.
Is there a way to standardize/align the Y1 & Y2 axis scales in log view? I tried in linear view by giving equal number of tick values on Y1 & Y2 axis. This gave me the tick values placement on corresponding values i.e 50 of Y1 to 0.2 on Y2.
Best Regards,
Your question does not make sense to me. The Y1 and Y2 values are for different variables. Do you have a second Y variable? You need two values to determine a linear scale, but you've only told me that 50 <--> 0.2. Perhaps the zero values are the same?
Although I don't fully understand your question, look at the YAXIS and Y2AXIS statements, which enable you to create values for both axes. You might need to use the MIN= and MAX= options to ensure that the axes are compatible and that Y1=50 aligns with Y2=0.2.
data Have;
call streaminit(12345);
do i = 1 to 1000;
t = abs(rand("normal", 0, 5));
x = exp(t);
y = rand("Normal", 0, 50);
y2 = (0.2 / 50)*y;
if abs(x)>1 then output;
end;
run;
proc sgplot data=Have;
scatter x=x y=y;
scatter x=x y=y2 / y2axis;
xaxis type=log logbase=10
values=(10 100 500 1000 10000 50000);
yaxis values=(-150 to 150 by 50) valueshint grid;
y2axis values=(-0.40 to 0.40 by 0.2) valueshint grid;
run;
If you have more questions, I suggest you post data.
Basically, I need to present two different parameters data on Y1 & y2 respectively with a common X axis (an individual concentration plot). Y1 values has a range from 0.1 to 60000 & Y2 has 0.01 to 600. we need to present this in semi-log view & has a note for programmer from stats - "Scale axis such that 0.2 on Y2 axis corresponds to 50 on Y1-axis".
Great. Then you should be able to modify the code I posted.
I could see that, Y2 values were imputed or calculated in the above code - y2 = (0.2 / 50)*y;
However in reality, we have two separate variables Y1 & Y2 has the data which is independent in nature. In such a scenario, I am still not able to fix the issue.
Look again at my previous comment in which I wrote:
"look at the YAXIS and Y2AXIS statements, which enable you to create values for both axes. You might need to use the MIN= and MAX= options to ensure that the axes are compatible and that Y1=50 aligns with Y2=0.2."
Two points determine a line, so to align the axes, set the MIN= and MAX= options on both axes to be compatible on the linear scale that you want. Then, if necessary, make sure the number of tick marks is the same on both axes. This will ensure that the scales and tick marks are aligned.
As always, if you provide data and code, we can provide more specific answers.
Hello, I have following test data to check..Thank you.
proc delete data = work._all_;run;
DATA test;
INFILE DATALINES;
INPUT subjet $ X Y1 Y2;
DATALINES4;
1 -11 . 12.5
1 -5 . 50.34
1 1 0.1 .
1 2 0.1 10.1
1 15 6450.2 0.01
1 28 22768.87 0.01
1 67 . 136
1 100 13078 36.12
1 257 4651 10
1 301 0.1 .
1 358 . 0.01
;;;;
run;
proc template;
define statgraph plot;
begingraph;
layout datapanel classvars=(subjet) / columns=1 rows=1 headerlabelattrs=(color=black weight=bold)
rowaxisopts=(type = log logopts=(base= 10 viewmin = 0.1 viewmax = 100000 TICKVALUELIST=(0.1 1 10 100 1000 10000 100000 ) ))
row2axisopts= (type = log logopts=(base= 10 viewmin = 0.01 viewmax = 10000 TICKVALUELIST=(0.01 0.1 1 10 100 1000 10000)));
layout prototype /;
SeriesPlot X=x Y=y1/ group=dose display=all name='y1' lineattrs=(color=black) markerattrs=(symbol=squarefilled color=black);
SeriesPlot X=x Y=y2 / group=dose yaxis=y2 display=all name='y2' lineattrs=(color=black pattern=SHORTDASH) markerattrs=(symbol=circle color=black);
endlayout;
sidebar / align=bottom;
discretelegend 'y1' 'y2' / ;
endsidebar;
endlayout;
endgraph;
end;
run;
proc sgrender data=test template=plot;
run;
Looks good to me.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.