简体   繁体   English

按 ID 组织 ODS 输出

[英]Organize ODS output by an ID

I need to create 3 graphs for each facility and output these onto 1 page.我需要为每个设施创建 3 个图表并将它们输出到 1 页。 I have 600 facilities to do this for so I will have a 600 page document.我有 600 个设施来做这件事,所以我将有一个 600 页的文件。 I have created my graphs using the code below.我使用下面的代码创建了我的图表。 If I specify a "where ID=X" in the proc sgplot statement, it outputs everything fine, but only for facility X. If I don't, it prints Graph 1 for every facility before going to the next graph.如果我在 proc sgplot 语句中指定“where ID=X”,它会输出一切正常,但仅适用于设施 X。如果我不这样做,它会在转到下一个图表之前为每个设施打印图表 1。 I'm guessing I need a macro... does anyone have any advice?我猜我需要一个宏...有人有什么建议吗?

OPTIONS orientation=vertical nodate;

ods rtf file="C:\Users\filename.rtf" STYLE=Styles.rtf;
ods listing close;
ods noproctitle  ;
ODS ESCAPECHAR='^';
title ; footnote;

*First graph;

ods graphics on / height=2.7 in width=8in;
ods rtf startpage=NOW;
ods rtf text= "^{style[fontweight=bold fontsize=11pt textalign=c] Employees}";
ods graphics/noborder;

 
proc sort data=clean4; by ID warehouse county; run;
proc sgplot data=clean4;
by pfi name;
     title2 "ID= #byval(ID) ";

      title3 "Name: #byval(warehouse) ";

      title4 "County: #byval(county) ";

series x=date y=emp  /  markers markerattrs=(symbol=CircleFilled color=blue) lineattrs=(color=blue thickness=2 pattern=1 ) legendlabel='Number of Employees' dataskin=pressed; 
   yaxis  label='Count' valueattrs=(size=11pt) labelattrs=(size=11pt weight=bold) offsetmin=0  integer;
   xaxis label='Date'  valueattrs=(size=11pt) labelattrs=(size=11pt weight=bold)  ;
      option NOBYLINE;

run;

*Second graph;

ods graphics on / height=2.7 in width=8in;
ods rtf startpage=NO;
ods rtf text=' ';
ods rtf text= "^{style[fontweight=bold fontsize=12pt textalign=c] Hats used daily}";
ods graphics/noborder;

proc sort data=clean4; by ID; run;
proc sgplot data=clean4;
 by ID;
title2; title3;

series x=date y=hats  /  markers markerattrs=(symbol=CircleFilled color=red)
      lineattrs=(color=red thickness=2 pattern=1 ) legendlabel='Number of hats used' dataskin=pressed; 
      yaxis  label='Count' valueattrs=(size=11pt) labelattrs=(size=11pt weight=bold) fitpolicy=thin 
      offsetmin=0 integer;
   xaxis label='Date'  valueattrs=(size=11pt) labelattrs=(size=11pt weight=bold)  ;

run;


*Third graph;

ods graphics on / height=2.7 in width=8in;
ods rtf startpage=NO;
ods rtf text=' ';
ods rtf text= "^{style[fontweight=bold fontsize=11pt textalign=c] LOESS}";
ods graphics/noborder;


proc sort data=clean4; by ID; run;
proc sgplot data=clean4;
      by ID;
      loess y=var1 x=date/ legendlabel="LOESS" lineattrs=(color=blue)
            FILLEDOUTLINEDMARKERS MARKERFILLATTRS=(color=black);
      yaxis  label='LOESS Plot' valueattrs=(size=11pt) labelattrs=(size=11pt weight=bold) offsetmin=0;

    xaxis label='Date'  valueattrs=(size=11pt) labelattrs=(size=11pt weight=bold) THRESHOLDMIN=0 
     THRESHOLDMAX=0  ;
 option NOBYLINE;

run;

ods rtf close;
ods listing ;

Because you are using the same data set clean4 for producing output in three different ways for each ID you need to change only a minimal amount of code when you convert to macro ( macroize ) the existing code.因为您使用相同的数据集clean4以三种不同方式为每个 ID 生成输出,所以当您将现有代码转换为宏 ( macroize ) 时,您只需更改最少量的代码。

Two steps两步

  • macroize existing code to operate on a single 'ID' value (the do'er)宏化现有代码以对单个“ID”值进行操作(执行者)
  • run the macro for each ID (the run'er)为每个 ID 运行宏(运行程序)

Do'er做人

%macro doReport(ID=);
  * move the sort to the top;
  * only need to sort the data once (for your situation);

  proc sort data=clean4 out=clean4_oneID; 
    by ID warehouse county; 
    where ID = "&ID";
  run;

  * Place all the graphing code here;
  * change all the 'clean4' data set references to 'clean4_oneID';

%mend;

Run'er跑儿

* Place ODS RTF and settings here;

* obtain list of each id;

proc sort nodupkey data=clean4 out=id_list; by id; run;

* 'stackingly' invoke macro for each id;

data _null_;
  set id_list;
  call execute (cats('%nrstr(%doReport(ID=',id,'))');
run;

* stacked execute code will now be submitted by SAS supervisor;

* close the RTF here;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM