Data visualization with SAS programming

Why Conditional not work in GTL?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Why Conditional not work in GTL?

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;

SGRender30.png


Accepted Solutions
Solution
‎05-15-2014 12:12 AM
SAS Super FREQ
Posts: 925

Re: Why Conditional not work in GTL?

Remove the eval() from the expression. It should just be max(_NPIC). For "if" conditions, the eval is not necessary.

View solution in original post


All Replies
SAS Super FREQ
Posts: 925

Re: Why Conditional not work in GTL?

Were there any warning messages in the log?

Occasional Contributor
Posts: 7

Re: Why Conditional not work in GTL?

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!

Solution
‎05-15-2014 12:12 AM
SAS Super FREQ
Posts: 925

Re: Why Conditional not work in GTL?

Remove the eval() from the expression. It should just be max(_NPIC). For "if" conditions, the eval is not necessary.

SAS Super FREQ
Posts: 925

Re: Why Conditional not work in GTL?

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.

Occasional Contributor
Posts: 7

Re: Why Conditional not work in GTL?

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.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 467 views
  • 3 likes
  • 2 in conversation