【问题标题】:SAS-Dynamically Writing Bar Charts to Excel workbook in SAS MacroSAS-在 SAS 宏中将条形图动态写入 Excel 工作簿
【发布时间】:2015-05-26 18:04:54
【问题描述】:

我正在尝试动态生成条形图并将其导出到 Excel 工作簿。我的宏提取某些不同的标识符代码并为每个相应的 ID 创建两个汇总表(prov_&x 表和 prov_revcd_&x)并填充到单个 Excel 表中。但是,我无法成功地为数据生成条形图并导出到 Excel。下面是代码的精简版。我删除了创建 prov_&x 表和 prov_revcd_&x 表的步骤,以帮助使帖子尽可能简洁。我尝试使用 GOUT 函数和 NAME 函数,然后显式调用它们,但这似乎不起作用。欢迎任何建议,我知道我的宏代码有点草率,但它会生成表格,所以一旦我可以生成条形图,我就会清理。

另外,我可以在我的结果查看器中看到图表正在生成,所以我假设问题在于我如何尝试将它们引用到工作簿。谢谢!

%macro runtab(x);

/*Create summary chart for generating graph of codes billed per month*/
proc sql;
CREATE TABLE summary_&x AS
select DISTINCT month, COUNT (CH_ICN) AS ICN_Count, CLI_Revenue_Cd_Category_Cd
FROM corf_data1_sorted
WHERE BP_Billing_Prov_Num_OSCAR=&x
group by month ,CLI_Revenue_Cd_Category_Cd;
run;

/*Create a graph of Services Per Month and group by the Revenue Code*/
proc sgplot data=summary_&x NAME= 'graph_&x';
  title 'Provider Revenue Analysis';
  vbar month / response=ICN_count group=CLI_Revenue_Cd_Category_Cd stat=sum
       datalabel datalabelattrs=(weight=bold);
  yaxis grid  label='Month';
  run;
%mend runtab;


/*Create a macro variable of all the codes */
proc sql noprint;
  select BP_Billing_Prov_Num_OSCAR
  into :varlist separated by ' ' /*Each code in the list is sep. by a single space*/
from provider;
quit;


%let cntlist = &sqlobs; /*Store a count of the number of oscar codes*/
%put &varlist; /*Print the codes to the log to be sure our list is accurate*/



/*write a macro to generate the output tables*/
%macro output(x);


ods tagsets.excelxp options(sheet_interval='none' sheet_name="&x");

proc print data=prov_&x;
run;

proc print data=prov_revcd_&x;
run;

proc print data=graph_&x;
run;  

%mend;

/*Run a loop for each oscar code. Each code will enter the document generation loop*/
%macro loopit(mylist);
    %let else=;
   %let n = %sysfunc(countw(&mylist)); /*let n=number of codes in the list*/
    data
   %do I=0 %to &n;
      %let val = %scan(&mylist,&I); /*Let val= the ith code in the list*/
    %end;


   %do j=0 %to &n;
      %let val = %scan(&mylist,&j); /*Let val= the jth code in the list*/
/*Run the macro loop to generate the required tables*/
%runtab(&val);


%output(&val);


   %end;
   run;
%mend;


/*Run the macro loop over the list of significant procedure code values*/


ods tagsets.excelxp file="W:\user\test_wkbk.xml";


%loopit(&varlist)


ods tagsets.excelxp close;

【问题讨论】:

    标签: sas sas-macro sas-ods


    【解决方案1】:

    很遗憾,您无法使用 ODS TAGSETS.EXCELXP 导出图表。

    如果您需要导出图表,您有几个选择。

    1. 使用 ODS Excel,在 SAS 9.4 更新的维护版本中可用。有关更多信息,请参阅Chris H's blog post。它与 Tagsets.ExcelXP 非常相似,但并不完全相同。它确实会生成一个“真实”的 Excel 文件 (.xlsx)。
    2. 使用 TAGSETS.MSOFFICE2K 或常规 HTML 创建 Excel 可以读取的 HTML 文件。 SAS 技术支持分析师 Chevell Parker 有几篇关于不同选项的论文,例如 this one
    3. 使用 DDE 将图像写入 excel 文件。不是首选选项,但出于完整性考虑。

    还有一个新的过程 - proc mschart - 在 SAS 9.4 TS1M3 中启用一两个月后,它将在 ODS EXCEL 中生成 Excel 图表(即,不是图像,而是告诉 Excel请在此处提供图表)。

    【讨论】:

    • 感谢您的建议@Joe!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多