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

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

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

5 REPLIES 5
DanH_sas
SAS Super FREQ

Were there any warning messages in the log?

Happydragon
Calcite | Level 5

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!

DanH_sas
SAS Super FREQ

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

DanH_sas
SAS Super FREQ

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.

Happydragon
Calcite | Level 5

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.

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
  • 5 replies
  • 1122 views
  • 3 likes
  • 2 in conversation