An SQLPLAN error might occur when referencing a variable created in an inline view with a CASE expression


An SQLPLAN error might occur under the following circumstances:

The error might look similar to the following:

ERROR: sqlplan internal error: Cannot find symbol le, var=6, tag=0009.
This message can be caused by attempting to make correlated references between two different items on a single FROM clause.

The only workaround is to split the query into two queries. In this split, the first query should create a table by running the code that was previously in the inline view. Then, in the second query, this table replaces the inline view.

See the Full Code section for sample code.

Full Code

The sample code below lists an example of code that would generate the error.

data test;
t1001118=0;
applino=1;
run;

proc sql;                                             
create table rai1001 as                               
select                                                
     case when le = 99 then 'LE99'                    
          when le = 0  then 'LE0'                     
          when le = 1  then 'LE1'                     
          else 'err'                                  
          end as le_s,                                
     sum(flag1) as Referrals                          
from ( select                                         
            case when flag1 = 1 then 1                
                 else 2                               
                 end as le,                           
             flag1                                    
       from (select                                   
                  case when not t1001118 = 0 then 1   
                       else 0                         
                       end as flag1  ,                
                  count(distinct applino) as ken      
             from test                              
             )                                        
       )                                              
group by le_s ;                                      
quit;