首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按ID组织ODS输出

按ID组织ODS输出
EN

Stack Overflow用户
提问于 2020-10-23 18:09:56
回答 1查看 95关注 0票数 0

我需要为每个设施创建3个图表,并将其输出到1页。我有600个设施来做这件事,所以我将有一个600页的文件。我使用下面的代码创建了我的图表。如果我在proc语句中指定了一个"where ID=X“,那么它输出的一切都很好,但只输出设施X。如果没有,它会在进入下一个图之前为每个工具打印图1。我猜我需要一个宏..。有人有什么建议吗?

代码语言:javascript
复制
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 ;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-24 04:00:32

由于您使用相同的数据集clean4以三种不同的方式为每个ID生成输出,所以在将现有代码转换为宏(宏化)时,只需更改最小数量的代码。

两步

  • 宏化现有代码以操作单个“ID”值(do‘’er)
  • ,为每个ID(run‘’er)

运行宏

Do‘’er

代码语言:javascript
复制
%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

代码语言:javascript
复制
* 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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64505273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档