Using dynamic variable in FLYOVER= in table template

Reply
Occasional Contributor
Posts: 7

Using dynamic variable in FLYOVER= in table template

Hi everyone,

I have a question regarding on table template.  Here is my code:


proc template;
    define table table.tsttmpl;
        dynamic _colhdr_ _flyover_ _bgcolor_ = 'blue';
        define column col;
            generic = on;
            define header colhdr;
                text _colhdr_;
                style = {flyover = _flyover_ foreground=black backgroundcolor=_bgcolor fontweight=bold};
            end;
            header = colhdr;
        end;
    end;
run;

I defined a dynamic variable _flyover_ and wished to use it when applying this template:


ods _all_ close;
ods tagsets.excelxp file = 'class.xml' style = sasweb;

data _null_;
    set sashelp.class;
    file print ods = ( template = 'table.tsttmpl'
        columns=(
        col = name(generic=on dynamic=(_colhdr_='Student Name' _flyover_ = 'SASHELP.CLASS.NAME' _bgcolor_ = 'green'))
        col = sex(generic=on dynamic=(_colhdr_='Gender' _flyover_ = 'SASHELP.CLASS.SEX'))
        )
    );
    put _ods_;
run;

ods tagsets.excelxp close;

But when I submit my code,  I got an error in PROC TEMPLATE:

329  proc template;
330      define table table.tsttmpl;
331          dynamic _colhdr_ _flyover_ _bgcolor_ = 'blue';
332          define column col;
333              generic = on;
334              define header colhdr;
335                  text _colhdr_;
336                  style = {flyover = _flyover_ foreground=black backgroundcolor=_bgcolor
                                                  ----------
                                                  79
                                                  76
336! fontweight=bold};

ERROR 79-322: Expecting a (.
ERROR 76-322: Syntax error, statement will be ignored.
337              end;
338              header = colhdr;
339          end;
340      end;
WARNING: Object will not be saved.
341  run;

I understand this is because FLYOVER= expects an quoted string. Is there any workaround?

Thanks in advance.

Super Contributor
Posts: 644

Re: Using dynamic variable in FLYOVER= in table template

Suggested workaround:

%Macro Flyaround_Tmplt (target) ;

     %Global _flyaround_  ;

     %Let  _flyaround_ = &target ;

    

     Proc template ....  

                     style = {flyover = "&_flyover_" foreground=black backgroundcolor=_bgcolor fontweight=bold};

               etc

     Run ;

%Mend ;


Then


%Flyaround_Tmplt (SASHELP.CLASS.SEX) ;

...

ods tagsets.excelxp file = 'class.xml' style = sasweb;

data _null_;

...

        col = sex(generic=on dynamic=(_colhdr_='Gender' _flyover_ = "&_flyover_"))

...

run ;


It means recompiling the template each time you want a different _flyover_ but that is a relatively small penalty


Richard

Occasional Contributor
Posts: 7

Re: Using dynamic variable in FLYOVER= in table template

Posted in reply to RichardinOz

Thanks Richard for your reply. In my previous code, i wanted to use the column col multiple times:

data _null_;

    set sashelp.class;

    file print ods = ( template = 'table.tsttmpl'

        columns=(

        col = name(generic=on dynamic=(_colhdr_='Student Name' _flyover_ = 'SASHELP.CLASS.NAME' _bgcolor_ = 'green'))

        col = sex(generic=on dynamic=(_colhdr_='Gender' _flyover_ = 'SASHELP.CLASS.SEX'))

        )

    );

    put _ods_;

run;

So I cannot run my program as your ways. But again, thanks.

Ask a Question
Discussion stats
  • 2 replies
  • 225 views
  • 0 likes
  • 2 in conversation