BookmarkSubscribeRSS Feed
Makkena
Calcite | Level 5
Hello,

I am using GTL and SGRENDER to plot the linear and Logarithmic graphs on the same page. Since, I am having zero values Logarithmic axis can not be plotted. I can see the note from the log NOTE: Log axis cannot support zero or negative values in the data range.
The axis type will be changed to LINEAR.
Since I need these values for plotting linear values I can not delete these values from the dataset. Is there anyway we could force
to use log scale or subset the data in the GTL code for the log plot? Please see the test code below.


proc template;
define statgraph sgplot7;
dynamic __BYLINE__ _ticklist_ timevar yvar trtvar sidvar
_title0 _title1 _title2 _title3
_title4 _title5 _title6 _title7 _title8 _title9 _title10
_footnote1 _footnote2 _footnote3 _footnote4 _footnote5
_footnote6 _footnote7 _footnote8 _footnote9 _footnote10;
nmvar _xoffset_min _xoffset_max _xmin _xmax _xorder
_yoffset_min _yoffset_max _ymin _ymax;

begingraph;
layout lattice /columns=2;

layout overlay / xaxisopts=(
type=linear offsetmin=_xoffset_min offsetmax=_xoffset_max
linearopts=( /* tickvaluelist=(&_xorder) */
viewmin=_xmin
viewmax=_xmax ))
yaxisopts=(
type=linear offsetmin=_yoffset_min offsetmax=_yoffset_max
linearopts=( viewmin=_ymin viewmax=_ymax )
);
ScatterPlot X=timevar Y=yvar / markerattrs=(color=black)
LegendLabel="mean"
NAME="scat";
endlayout;
cell;
cellheader;
entry "Semi-log" / textattrs=GraphLabelText;
endcellheader;

layout overlay / xaxisopts=(
type=linear offsetmin=_xoffset_min offsetmax=_xoffset_max
linearopts=( /* tickvaluelist=(&_xorder) */
viewmin=_xmin
viewmax=_xmax ))
yaxisopts=(
type=log offsetmin=_yoffset_min offsetmax=_yoffset_max
logopts=( Base=10 ));

ScatterPlot X=timevar Y=yvar / markerattrs=(color=black)
LegendLabel="mean" NAME="scat";

endlayout;
endcell;
endlayout;

endgraph;
end;
run;


title;
footnote;

%let _xvar=visit;
%let _yvar=m_wtgain;
proc sgrender data=sashelp.bweight template=sgplot7 ;
dynamic timevar="&_xvar" yvar="&_yvar" ;
run;

I have sent this to the SAS support and they replied we do not have any options to force or subset the data at the moment.

Thanks,
Makkena Message was edited by: Makkena
4 REPLIES 4
DanH_sas
SAS Super FREQ
I would copy the X variable to an X2 column and replace all of the zeros with missing values. Then, use that column for your log axis. Let me know if that helps.

Dan
Makkena
Calcite | Level 5
Thanks Dan. I have created a new variable by setting the <=0 values to missing. Unfortunately, that did not like it. I got a warning message in the log. The ScatterPlot statement named 'scat1' will not be drawn because one or more of the required arguments were not supplied.

proc template;
define statgraph sgplot7;
dynamic __BYLINE__ _ticklist_ timevar yvar trtvar sidvar
_title0 _title1 _title2 _title3
_title4 _title5 _title6 _title7 _title8 _title9 _title10
_footnote1 _footnote2 _footnote3 _footnote4 _footnote5
_footnote6 _footnote7 _footnote8 _footnote9 _footnote10;
nmvar _xoffset_min _xoffset_max _xmin _xmax _xorder yvar1
_yoffset_min _yoffset_max _ymin _ymax;

begingraph;
layout lattice /columns=2;

layout overlay / xaxisopts=(
type=linear offsetmin=_xoffset_min offsetmax=_xoffset_max
linearopts=( /* tickvaluelist=(&_xorder) */
viewmin=_xmin
viewmax=_xmax ))
yaxisopts=(
type=linear offsetmin=_yoffset_min offsetmax=_yoffset_max
linearopts=( viewmin=_ymin viewmax=_ymax )
);
ScatterPlot X=timevar Y=yvar / markerattrs=(color=black)
LegendLabel="mean"
NAME="scat";
endlayout;
cell;
cellheader;
entry "Semi-log" / textattrs=GraphLabelText;
endcellheader;

layout overlay / xaxisopts=(
type=linear offsetmin=_xoffset_min offsetmax=_xoffset_max
linearopts=( /* tickvaluelist=(&_xorder) */
viewmin=_xmin
viewmax=_xmax ))
yaxisopts=(
type=log
logopts=( Base=10 ));

ScatterPlot X=timevar Y=yvar1 markerattrs=(color=black)
LegendLabel="mean" NAME="scat1";

endlayout;
endcell;
endlayout;

endgraph;
end;
run;


title;
footnote;

%let _xvar=visit;
let _yvar1=m_wtgain1;
%let _yvar=m_wtgain;
data weight;
set sashelp.bweight;
if m_wtgain le 0 then m_wtgain1=.;
else m_wtgain1=m_wtgain;
run;

proc sgrender data=weight template=sgplot7 ;
dynamic timevar="&_xvar" yvar="&_yvar" yvar1="&_yvar1";
run;

Setting bold is not displaying the whole message.


Message was edited by: Makkena Removed bold


Message was edited by: Makkena
MikeZdeb
Rhodochrosite | Level 12
hi ... so this is not a direct answer to the question, but just another way to look at the weight change data

if you want a display of logs of weight change, you know that you'll have to 'throw away' the zero and negative numbers

so, here's a non-GTL way of looking at the same data that looks slightly similar to your GTL plot

weight change is always 0 or positive
gain is blue, lose is red
this gives a 'log look' at both weight gain and weight loss
[pre]
*
rearranging data ... +/0 in one group, - in another
two groups
;
data bwt;
set sashelp.bweight (keep=visit m_wtgain);
select;
when (m_wtgain ge 0) do; group=1; lvisit=3*visit; end;
when (m_wtgain lt 0) do; group=2; lvisit=3*visit+1; end;
end;
lm_wtgain = abs(m_wtgain);
run;

* some SAS/Graph options;
goptions reset=all ftext="calibri" htext=1
device=gif xpixels=1000 ypixels=1000 gsfname=gout ;

axis1 label=(a=90 "MOM'S WEIGHT CHANGE (POUNDS)");

axis2 label=(a=90 "MOM'S WEIGHT CHANGE (POUNDS, LOG SCALE)")
logbase=10;

axis3 offset=(5,5)pct minor=none order=-0 to 10 by 1
major=(c=white) label=('VISIT')
value=(
tick=1 c=blue j=c "0" j=c "GAIN" tick=2 c=red j=c "0" j=c "LOSE" tick=3 ""
tick=4 c=blue j=c "1" j=c "GAIN" tick=5 c=red j=c "1" j=c "LOSE" tick=6 ""
tick=7 c=blue j=c "2" j=c "GAIN" tick=8 c=red j=c "2" j=c "LOSE" tick=9 ""
tick=10 c=blue j=c "3" j=c "GAIN" tick=11 c=red j=c "3" j=c "LOSE" tick=12 "");

symbol1 v=dot h=1 c=blue;
symbol2 v=dot h=1 c=red;

* for white space around the chart;
title1 ls=1;
title2 ls=1 a=90;
title3 ls=1 a=-90;
footnote1 ls=1;

*
two plots ... one regular, one log (base 10)
not printed ... used later in GREPLAY
;
filename gout dummy;

proc gplot data=bwt gout=plots;
plot lm_wtgain*lvisit=group / vaxis=axis1 haxis=axis3 nolegend name='one';
run;
plot lm_wtgain*lvisit=group / vaxis=axis2 haxis=axis3 nolegend name='two';
where lm_wtgain ne 0;
run;
quit;

goptions xpixels=2000;

* destination for output;
filename gout "z:\bwt.gif";

proc greplay igout=plots nofs;
tc sashelp.templt;
template h2;
tplay 1:one 2:two;
quit;

* chance to use KILL in SAS;
proc catalog c=plots kill;
run;
quit;
[/pre]
Makkena
Calcite | Level 5
Thanks Mike for your response. I have no issue with Non-GTL language which we had it already. I am using the new SG procedures and GTL language totake the advatange of the Graphics quality.
Dan, I see for some reason my early response was not posted properly. The solution you proposed did not work.
Thanks for all your replies,
Makkena

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2113 views
  • 0 likes
  • 3 in conversation