按 ID 组织 ODS 输出

Organize ODS output by an ID

我需要为每个设施创建 3 个图表并将它们输出到一页上。我有 600 个设施可以执行此操作,因此我将有一个 600 页的文档。我使用下面的代码创建了我的图表。如果我在 proc sgplot 语句中指定“where ID=X”,它会输出一切正常,但仅针对设施 X。如果我不这样做,它会在转到下一张图之前为每个设施打印图 1。我猜我需要一个宏...有人有什么建议吗?

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 ;

因为您使用相同的数据集 clean4 以三种不同的方式为每个 ID 生成输出,所以当您转换为宏 (macroize) 现有代码。

两步

  • 宏化现有代码以对单个 'ID' 值(执行者)进行操作
  • 运行每个ID的宏(运行'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;

运行'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;