在 PROC REPORT 中动态创建定义

Dynamically create define in a PROC REPORT

我有一个数据集 (liste_institution),其中包含我想要在 proc report 语句中“define”的所有变量名称。这是我的代码,当我不是动态地调用我的宏时(%create_institution(815);)。如果我将数据语句与调用执行一起使用(在我的代码中的注释中)它不起作用。原因似乎是当我使用调用执行时,代码未在 PROC REPORT 中解释,这就是它给我错误的原因。

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;

有没有一种简单的方法可以从包含列名的数据集在 PROC REPORT 中创建动态定义语句。

基本上,您对宏的工作原理和时间有误解。您需要在 proc 报告之前编译宏列表,但您不能使用 call execute,因为它实际上会执行代码。您需要创建一个宏变量。

最简单的方法如下:

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

这使得 &inslist 现在是机构列表(使用宏调用)。

您也可以使用 across 变量来简化此操作;您所拥有的是每个 ins 一行,其中一个变量具有该值(定义列名称),另一个变量具有数据 table 部分中的值。然后 SAS 将自动为每个 across 值创建列。跨变量是使 proc report 极其强大的原因之一。