在Base SAS中生成不在表格布局中的报表

时间:2009-02-26 21:53:11

标签: sas

我正在使用Base SAS 8.1(OpenVMS)编写报告。我需要它每次观察有1页...类似于下面。我找不到任何显示如何使用PROC PRINT或PROC REPORT执行此操作的内容。除了PUT语句之外,还有什么方法可以做到这一点吗?不幸的是,升级或添加模块不是一种选择。任何帮助表示赞赏。

标题文字观察ID 1

第1行文本----------------变量1

第2行文本----------------变量2

第3行文本----------------变量3

- 分页符 -

标题文字观察ID 2

第1行文本----------------变量1

第2行文本----------------变量2

第3行文本----------------变量3

- 分页符 -

1 个答案:

答案 0 :(得分:5)

如果您按观察编号转置数据集,那么proc report可以毫无问题地处理它。第h

/* test data -- each obs is identified by obsId */
data class;
  set sashelp.class;
  obsId = _n_;
run;

/* transpose the data */
proc transpose 
  data=class 
  out=report(rename=(_name_=var col1=value));
  var _all_;
  by obsId;
run;

/* change the varaible name into "Line 1 text ..." */
data report;
  drop line cLine dashes;
  length var cLine $30;
  dashes = repeat("-", 20-1);
  /* usual DoW */
  do line = 1 by 1 until (last.obsId);
    set report;
    by obsId;
    cLine = put(line, best.-l);
    var = "Line "||trim(cline)||" text "||dashes;
    output;
  end;
run;

/* print out one obs per page */
options nocenter;
proc report data=report nowd;
  column obsId var value;
  define obsId / " " group noprint;
  define var / " " display left;
  define value / " " display left;
  break after obsId / page;
  compute before obsId;
    id = put(obsId, best.-l);
    len = length(id);
    line @2 "Header Text Observation Id " iD $varying. len;
    line " ";
  endcomp;
run;

/* on lst, in part. 
Header Text Observation Id 1

 Line 1 text ------------------  Alfred
 Line 2 text ------------------  M
 Line 3 text ------------------            14
 Line 4 text ------------------            69
 Line 5 text ------------------         112.5
 Line 6 text ------------------             1

(new page)
Header Text Observation Id 2

 Line 1 text ------------------  Alice
 Line 2 text ------------------  F
 Line 3 text ------------------            13
 Line 4 text ------------------          56.5
 Line 5 text ------------------            84
 Line 6 text ------------------             2

(new page)
...
*/