user1842455
user1842455

Reputation: 95

Dynamically create define in a PROC REPORT

I have a dataset(liste_institution) that contain all the name of the variable that I want to "define" in my proc report statement. Here is my code that work when I call my macro not dynamically(%create_institution(815);). If I use the data statement with the call execute(in comment in my code) it not working. The reason seem to be that when I use the call execute the code is not interpreted in a PROC REPORT that is why it give me error.

proc report data =  ventes_all_inst4
                            missing split = "*" nowd
                            style(header)=[font_weight=bold background = #339966 foreground = white]
                            style(column)=[cellwidth=15cm];

    %macro create_institution(institution);

        define TOTAL_&institution. / display "TOTAL*($)" style(column)=[cellwidth=4cm];

    %mend;
            /* Give error when I use this data step */
            /*data _null_;
                set liste_institution;
                call execute('%create_institution(' || INS || ');');
            run;*/
            %create_institution(815);

run;

Is there an easy way to create dynamically define statement in a PROC REPORT from a dataset that contain the column name.

Upvotes: 0

Views: 1055

Answers (1)

Joe
Joe

Reputation: 63434

Basically, you have a misunderstanding of how macros work and timing. You need to compile the macro list previous to the proc report, but you can't use call execute because that actually executes code. You need to create a macro variable.

Easiest way to do it is like so:

proc sql;
  select cats('%create_institution(',ins,')')
    into :inslist separated by ' '
    from liste_institution
  ;
quit;

which makes &inslist which is now the list of institutions (with the macro call).

You also may be able to use across variables to allow this to be easier; what you'd have is one row per ins, with a single variable with that value (which defines the column name) and another single variable with the value that goes in the data table portion. Then SAS will automatically create columns for each across value. Across variables are one of the things that makes proc report extremely powerful.

Upvotes: 0

Related Questions