PROC报告:是否可以不打印特定行?

时间:2018-02-28 20:13:54

标签: sas proc-report

我正在使用PROC REPORT向Excel写一份报告。第一列被分组,我在它的某些值之前添加了一个断行。如果列符合某些条件,则此分隔行包含列的值。

例如

我的表包含以下行:

nom_var        |  val1       |   val2    | val3     |
_____________________________________________________
Identification |      .      |   .       |   .      |
Name           | Ou. Dj.     |   .       |   .      |
date B.        | 00/01/31    |   .       |   .      |
NAS            | 1122334     |   .       |   .      |
Revenues       |      .      |  .        |   .      |
               | R1 1250  $  | R2 1000 $ |   .      |
_____________________________________________________

在报告中我有:

_____________________________________________________
                    Identification
_____________________________________________________
Identification |      .      |   .       |   .      |
Name           | Ou. Dj.     |   .       |   .      |
date B.        | 00/01/31    |   .       |   .      |
NAS            | 1122334     |   .       |   .      |
____________________________________________________
                      Revenues
_____________________________________________________
Revenues       |      .      |  .        |   .      |
               | R1 1250  $  | R2 1000 $ |   .      |
_____________________________________________________

请问,我怎样才能恢复包含"识别"和"收入"在第一栏" nom_var"?

我的意思是:

Identification |      .      |   .       |   .      |

Revenues       |      .      |   .       |   .      |

这是我的代码:

ods listing close;

*options générales;
options topmargin=1in bottommargin=1in
        leftmargin=0.25in rightmargin=0.25in
;

%let fi=%sysfunc(cat(%sysfunc(compress(&nom)),_portrait_new.xls));

ods tagsets.ExcelXP path="&cheminEx." file="&fi" style=seaside
options(autofit_height="yes"
        pagebreaks="yes"
        orientation="portrait"
        papersize="letter"
        sheet_interval="none"
        sheet_name="Infos Contribuable"
        WIDTH_POINTS = "12" WIDTH_FUDGE = ".0625" /* absolute_column_width est en pixels*/
        absolute_column_width="120,180,160,150"
        );

ods escapechar="^";

*rapport1;
/*contribuable*/
proc report data=&lib..portrait nowindows missing spanrows noheader
    style(report)=[frame=box rules=all
                    foreground=black Font_face='Times New Roman' font_size=10pt
                    background=none]
    style(column)=[Font_face='Times New Roman' font_size=10pt just=left]

;
    /*entête du tableau est la première variable de la table ==> à gauche du rapport */
    define nom_var / group order=data style(column)=[verticalalign=middle
                                        background=#e0e0e0  /* gris  */
                                        foreground=blue
                                        fontweight=bold
                                        ];
    /* Contenu */
    define valeur_var1 / style(column)=[verticalalign=top];
    define valeur_var2 / style(column)=[verticalalign=top];
    define valeur_var3 / style(column)=[verticalalign=top];

    compute before nom_var / style=[verticalalign=middle background=#e0e0e0
                                        foreground=blue fontweight=bold font_size=12pt];
        length rg $ 50;
        if nom_var in ("Identification","Actifs", "Revenus") then do;
            rg= nom_var;
            len=50;
        end;
            else do;
                rg="";
                len=0;
            end;
        line rg $varying50. len;
    endcomp ;

    title j=center height=12pt 'Portrait du contribuable';

run;

ods tagsets.ExcelXP close;
ods listing;

1 个答案:

答案 0 :(得分:0)

您有一个人工数据结构,其格式不适合输出信息行的任务。

此示例显示了数据步骤如何调整数据,以便您有一个mySection变量来组织感兴趣的nom_var行引入的行(IdentificationRevenues

新的数据安排更适合您正在进行的任务。

data have;
length nom_var val1 val2 val3 $50;
infile cards dlm='|';
input 
nom_var           val1          val2       val3     ;
datalines;
Identification |      .      |   .       |   .      |
Name           | Ou. Dj.     |   .       |   .      |
date B.        | 00/01/31    |   .       |   .      |
NAS            | 1122334     |   .       |   .      |
Revenues       |      .      |  .        |   .      |
               | R1 1250  $  | R2 1000 $ |   .      |
run;

调整原始数据,因此存在分类mySection

data need;
  set have;
  retain mySection;
  select (nom_var);
    when ('Identification') mySection = nom_var;
    when ('Revenues') mySection = nom_var;
    otherwise OUTPUT;   * NOTE: Explicit OUTPUT means there is no implicit OUTPUT, which means the rows that do mySection= are not output;
  end;
run;

使用新变量(mySection)进行分组(compute before),但保持其列隐藏(noprint

proc report data=need;
  column mySection nom_var val1 val2 val3;
  define mySection / group noprint;
  compute before mySection;
    line mySection $50.;
  endcomp;
run;