Dear all, I try to use conditional logic to control the output in GTL. But it doesn't work. see code below.
what I expect is, when pass variable NPIC=2 into _NPIC, we will got second cell show in the graph. but what I got is not as my expect. See the title, _NPIC should got the variable value from data.
proc template;
define statgraph sgdesign1;
dynamic _HEIGHT _WEIGHT _HEIGHT2 _AGE _NPIC;
begingraph;
layout lattice _id='lattice' / columndatarange=data columngutter=10 rowdatarange=data rowgutter=10 rows=2;
entrytitle "aaaa" eval(mean(_Npic)) '--' eval(max(_NPIC)=2);
layout overlay _id='overlay' /;
scatterplot _id='scatter' x=_HEIGHT y=_WEIGHT / name='scatter';
endlayout;
if ( eval(max(_NPIC)=2) )
layout overlay _id='overlay2' /;
scatterplot _id='scatter2' x=_HEIGHT2 y=_AGE / name='scatter2';
endlayout;
endif;
sidebar / align=bottom spacefill=false;
discretelegend _id='legend3' 'scatter' / border=true displayclipped=true halign=center opaque=true valign=center;
endsidebar;
endlayout;
endgraph;
end;
run;
proc sort data=sashelp.class out=class;
by sex;
run;
data class;
set class;
x2=height;
npic=2;
run;
proc sgrender data=CLASS template=sgdesign1;
where sex='F';
dynamic _HEIGHT="HEIGHT" _WEIGHT="WEIGHT" _HEIGHT2="X2" _AGE="AGE" _NPIC="NPIC";
run;
Remove the eval() from the expression. It should just be max(_NPIC). For "if" conditions, the eval is not necessary.
Were there any warning messages in the log?
No. log is clean. my sas version is SAS 9.2 TS Level 2M9.
Maybe you can run my code in your SAS.
Thanks a lot!
Remove the eval() from the expression. It should just be max(_NPIC). For "if" conditions, the eval is not necessary.
To further explain, we use the eval() to differentiate an expression from a variable in plot statements and other situations. However, in an "if" condition, it can only be an expression. Therefore, we do not expect you to use an eval() there. Actually using eval() was causing your expression to not be processed correctly.
thanks for your reply. It work correctly after remove eval(). But why it doesn't work if I remove max()?
At first, I try to use
if (_NPIC=2)
but it doesn't work.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.